Home All Groups Group Topic Archive Search About

Help on MailItems and AD addresses

Author
23 Feb 2007 12:54 AM
Dave Booker
In C#/.NET 2.0: How can I reply to an Email address retrieved from an
Exchange server MailItem?

I am using Interop Outlook.MAPIFolder to retrieve Outlook.MailItem's.  I
want to send an automated response to the sender of each MailItem, but
MailItem.SenderEmailAddress is something like "/O=COMPANY/OU=ADMIN
GROUP/CN=RECIPIENTS/CN=USERNAME".  I don't know what that is, though I
assume it has something to do with active directory.

I can send messages using SMTP addresses in my current environment.  Is
there a straightforward way to retrieve the SMTP address for an Exchange user
in a situation like this?

MailItem also exposes a tempting public method "Reply()", which produces
another MailItem object with a method "Send()", but when I call it I get an
exception trying to cast the Reply to a MailItem.  Can anyone offer a working
example of how to reply using MailItems?

Author
23 Feb 2007 3:56 PM
Dmitry Streblechenko
This is a normal EX type address. How exactly are you sending messages? If
you have the EX provider in your current profile, using an EX address should
not pose any problems.
If you are using Outlook 2007, you can use ExchangeUser.PrimarySmtpAddress
property.

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy  - Outlook, CDO
and MAPI Developer Tool

Show quote
"Dave Booker" <dbooksta@newsgroup.nospam> wrote in message
news:79C54BFC-7B95-40CC-B64D-8EBC6694DC8F@microsoft.com...
> In C#/.NET 2.0: How can I reply to an Email address retrieved from an
> Exchange server MailItem?
>
> I am using Interop Outlook.MAPIFolder to retrieve Outlook.MailItem's.  I
> want to send an automated response to the sender of each MailItem, but
> MailItem.SenderEmailAddress is something like "/O=COMPANY/OU=ADMIN
> GROUP/CN=RECIPIENTS/CN=USERNAME".  I don't know what that is, though I
> assume it has something to do with active directory.
>
> I can send messages using SMTP addresses in my current environment.  Is
> there a straightforward way to retrieve the SMTP address for an Exchange
> user
> in a situation like this?
>
> MailItem also exposes a tempting public method "Reply()", which produces
> another MailItem object with a method "Send()", but when I call it I get
> an
> exception trying to cast the Reply to a MailItem.  Can anyone offer a
> working
> example of how to reply using MailItems?
>
Author
23 Feb 2007 4:16 PM
Dave Booker
I'm used to sending messages using System.Net.Mail.SmtpClient.  (This is my
first foray into Exchange Server.)  We're still using Office 2003.

If there's a straightforward way for me to send Emails to an EX address
using C# that would meet my needs.  Can you point me to docs or exampels?

Also can you point me to documentation on the construction and validation of
EX addresses?


Show quote
"Dmitry Streblechenko" wrote:

> This is a normal EX type address. How exactly are you sending messages? If
> you have the EX provider in your current profile, using an EX address should
> not pose any problems.
> If you are using Outlook 2007, you can use ExchangeUser.PrimarySmtpAddress
> property.
>
> Dmitry Streblechenko (MVP)
> http://www.dimastr.com/
> OutlookSpy  - Outlook, CDO
> and MAPI Developer Tool
>
> "Dave Booker" <dbooksta@newsgroup.nospam> wrote in message
> news:79C54BFC-7B95-40CC-B64D-8EBC6694DC8F@microsoft.com...
> > In C#/.NET 2.0: How can I reply to an Email address retrieved from an
> > Exchange server MailItem?
> >
> > I am using Interop Outlook.MAPIFolder to retrieve Outlook.MailItem's.  I
> > want to send an automated response to the sender of each MailItem, but
> > MailItem.SenderEmailAddress is something like "/O=COMPANY/OU=ADMIN
> > GROUP/CN=RECIPIENTS/CN=USERNAME".  I don't know what that is, though I
> > assume it has something to do with active directory.
> >
> > I can send messages using SMTP addresses in my current environment.  Is
> > there a straightforward way to retrieve the SMTP address for an Exchange
> > user
> > in a situation like this?
> >
> > MailItem also exposes a tempting public method "Reply()", which produces
> > another MailItem object with a method "Send()", but when I call it I get
> > an
> > exception trying to cast the Reply to a MailItem.  Can anyone offer a
> > working
> > example of how to reply using MailItems?
> >
>
>
>
Author
23 Feb 2007 8:08 PM
Dmitry Streblechenko
If you are sending to an EX address, you obviously need to do that through
the Exchange provider - anything based on Extended MAPI (that includes
Outlook Object Model and CDO 1.21) will let you do that.
If you are retrieving the address through OOM, why not use OOM to send the
message?
If you absolutely need to send through SMTP, you can retrieve the SMTP proxy
addresses using Extended MAPI (C++/Dephi only), CDO 1.21 or <plug>
Redemption (which also exposes the AddressEntry.SmtpAddress for all address
entries on all version of Outlook) </plug>: essentially you will need to
retrieve PR_EMS_AB_PROXY_ADDRESSES multivalued property with all proxy
addresses for for the given EX address entry.

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy  - Outlook, CDO
and MAPI Developer Tool

Show quote
"Dave Booker" <dbooksta@newsgroup.nospam> wrote in message
news:39A8702B-6F43-4744-8865-06D815DD8CB8@microsoft.com...
> I'm used to sending messages using System.Net.Mail.SmtpClient.  (This is
> my
> first foray into Exchange Server.)  We're still using Office 2003.
>
> If there's a straightforward way for me to send Emails to an EX address
> using C# that would meet my needs.  Can you point me to docs or exampels?
>
> Also can you point me to documentation on the construction and validation
> of
> EX addresses?
>
>
> "Dmitry Streblechenko" wrote:
>
>> This is a normal EX type address. How exactly are you sending messages?
>> If
>> you have the EX provider in your current profile, using an EX address
>> should
>> not pose any problems.
>> If you are using Outlook 2007, you can use
>> ExchangeUser.PrimarySmtpAddress
>> property.
>>
>> Dmitry Streblechenko (MVP)
>> http://www.dimastr.com/
>> OutlookSpy  - Outlook, CDO
>> and MAPI Developer Tool
>>
>> "Dave Booker" <dbooksta@newsgroup.nospam> wrote in message
>> news:79C54BFC-7B95-40CC-B64D-8EBC6694DC8F@microsoft.com...
>> > In C#/.NET 2.0: How can I reply to an Email address retrieved from an
>> > Exchange server MailItem?
>> >
>> > I am using Interop Outlook.MAPIFolder to retrieve Outlook.MailItem's.
>> > I
>> > want to send an automated response to the sender of each MailItem, but
>> > MailItem.SenderEmailAddress is something like "/O=COMPANY/OU=ADMIN
>> > GROUP/CN=RECIPIENTS/CN=USERNAME".  I don't know what that is, though I
>> > assume it has something to do with active directory.
>> >
>> > I can send messages using SMTP addresses in my current environment.  Is
>> > there a straightforward way to retrieve the SMTP address for an
>> > Exchange
>> > user
>> > in a situation like this?
>> >
>> > MailItem also exposes a tempting public method "Reply()", which
>> > produces
>> > another MailItem object with a method "Send()", but when I call it I
>> > get
>> > an
>> > exception trying to cast the Reply to a MailItem.  Can anyone offer a
>> > working
>> > example of how to reply using MailItems?
>> >
>>
>>
>>
Author
24 Feb 2007 5:46 PM
Chad
Once you have this "/O=COMPANY/OU=ADMIN GROUP/CN=RECIPIENTS/CN=USERNAME"
address 90% of the battle is over.

That's AD-speak for who the recipient is.  If you want to send to that
address via System.Net.Mail, you can query AD for the actual email address
and use that:

make sure you include System.DirectoryServices; (requires a .NET added
reference)

DirectoryEntry de = new
DirectoryEntry("LDAP://[domain.com]/[O=COMPANY/OU=ADMIN
GROUP/CN=RECIPIENTS/CN=USERNAME]",
@"[domain\username]", "[password]");
[in the above, replace bracketed parts with your domain
information/credentials]
Then, there is probably a better way to get the email from here, but this is
a way that's worked for me:
DirectorySearcher ds = new DirectorySearcher();
ds.SearchRoot = de;
ds.Filter = "(SAMAccountName=*)"; //query for all aliases (SAMAccountName)
matching this "AD address"
ds.SearchScope = SearchScope.SubTree;

//simplistic results w/o error checking
SearchResult sr = ds.FindOne();
string alias= sr.Properties["SAMAccountName"][0]; //need to handle nulls/0
results/multiple results here
you can youse Properties["mail"] if you want the full email address and not
just the alias for alias@[domain.com].

Then you can send to it like normal

If you need more help you can try the System.DirectoryServices
documentation.  Make sure your LDAP is in upper case.

Show quote
"Dave Booker" wrote:

> In C#/.NET 2.0: How can I reply to an Email address retrieved from an
> Exchange server MailItem?
>
> I am using Interop Outlook.MAPIFolder to retrieve Outlook.MailItem's.  I
> want to send an automated response to the sender of each MailItem, but
> MailItem.SenderEmailAddress is something like "/O=COMPANY/OU=ADMIN
> GROUP/CN=RECIPIENTS/CN=USERNAME".  I don't know what that is, though I
> assume it has something to do with active directory.
>
> I can send messages using SMTP addresses in my current environment.  Is
> there a straightforward way to retrieve the SMTP address for an Exchange user
> in a situation like this?
>
> MailItem also exposes a tempting public method "Reply()", which produces
> another MailItem object with a method "Send()", but when I call it I get an
> exception trying to cast the Reply to a MailItem.  Can anyone offer a working
> example of how to reply using MailItems?
>
Author
25 Feb 2007 1:11 PM
Henning Krause [MVP - Exchange]
Hello,

actually, the address you get here is an Exchange legacy distinguished name,
used by Exchangg 5.5. Since Active Directory uses normal distinguished
names, you can not use the legacyExchangeDN to bind to the object.

You must perform an LDAP search to get the object:

DirectoryEntry entry = new DirectoryEntry("dc", "username", "password",
AuthenticationTypes.Secure);
DirectorySearcher searcher = new DirectorySearcher(entry,
"(legacyExchangeDN=/O=COMPANY/OU=ADMIN GROUP/CN=RECIPIENTS/CN=USERNAME)");
SearchResult sr = searcher.FindOne();
if (sr == null)
{
    // User not found
}
else
{
    // User found
}

Substitute the "dc" with something like this: LDAP://[domain.com]/DC=Domain,
DC=com.

If your Active Directory spans more than one domain, you're probably better
of using GC://[domain.com]/DC=Domain, DC=com, where "DC=Domain, DC=COM"
should be the distinguished name of the Root domain. This will perform a
search on a Global Catalog server, which contains information about all
objects in a forest.

Note that you can omit the [domain.com] completely, if the computer you are
using is in the domain.

Best regards,
Henning Krause



Show quote
"Chad" <C***@discussions.microsoft.com> wrote in message
news:ED931658-5495-42AE-865A-F17B079D027A@microsoft.com...
> Once you have this "/O=COMPANY/OU=ADMIN GROUP/CN=RECIPIENTS/CN=USERNAME"
> address 90% of the battle is over.
>
> That's AD-speak for who the recipient is.  If you want to send to that
> address via System.Net.Mail, you can query AD for the actual email address
> and use that:
>
> make sure you include System.DirectoryServices; (requires a .NET added
> reference)
>
> DirectoryEntry de = new
> DirectoryEntry("LDAP://[domain.com]/[O=COMPANY/OU=ADMIN
> GROUP/CN=RECIPIENTS/CN=USERNAME]",
> @"[domain\username]", "[password]");
> [in the above, replace bracketed parts with your domain
> information/credentials]
> Then, there is probably a better way to get the email from here, but this
> is
> a way that's worked for me:
> DirectorySearcher ds = new DirectorySearcher();
> ds.SearchRoot = de;
> ds.Filter = "(SAMAccountName=*)"; //query for all aliases (SAMAccountName)
> matching this "AD address"
> ds.SearchScope = SearchScope.SubTree;
>
> //simplistic results w/o error checking
> SearchResult sr = ds.FindOne();
> string alias= sr.Properties["SAMAccountName"][0]; //need to handle nulls/0
> results/multiple results here
> you can youse Properties["mail"] if you want the full email address and
> not
> just the alias for alias@[domain.com].
>
> Then you can send to it like normal
>
> If you need more help you can try the System.DirectoryServices
> documentation.  Make sure your LDAP is in upper case.
>
> "Dave Booker" wrote:
>
>> In C#/.NET 2.0: How can I reply to an Email address retrieved from an
>> Exchange server MailItem?
>>
>> I am using Interop Outlook.MAPIFolder to retrieve Outlook.MailItem's.  I
>> want to send an automated response to the sender of each MailItem, but
>> MailItem.SenderEmailAddress is something like "/O=COMPANY/OU=ADMIN
>> GROUP/CN=RECIPIENTS/CN=USERNAME".  I don't know what that is, though I
>> assume it has something to do with active directory.
>>
>> I can send messages using SMTP addresses in my current environment.  Is
>> there a straightforward way to retrieve the SMTP address for an Exchange
>> user
>> in a situation like this?
>>
>> MailItem also exposes a tempting public method "Reply()", which produces
>> another MailItem object with a method "Send()", but when I call it I get
>> an
>> exception trying to cast the Reply to a MailItem.  Can anyone offer a
>> working
>> example of how to reply using MailItems?
>>

AddThis Social Bookmark Button