Outlook: How to receive email from the Recipient field?

I am trying to get the email address entered in the To field to create a mail box.

I am trying to get the Recipient's Address property, which, according to VS, should provide me with an email.

Instead, I get a line that looks like this:

"/c=US/a=att/p=Microsoft/o=Finance/ou=Purchasing/s=Furthur/g=Joe" 

How can I get the email address in the recipient field?

My code is:

 List <string> emails = new List<string>(); if (thisMailItem.Recipients.Count > 0) { foreach (Recipient rec in thisMailItem.Recipients) { emails.Add(rec.Address); } } return emails; 
+8
c # visual-studio outlook vsto
source share
4 answers

Can you try this?

 emails.Add(rec.AddressEntry.Address); 

Link Link

EDIT:

I donโ€™t have a suitable testing environment, so Iโ€™m just guessing it all, but what about

 string email1Address = rec.AddressEntry.GetContact().Email1Address; 

or .Email2Adress or .Email3Address

Also have

 rec.AddressEntry.GetExchangeUser().Address 

which you can try.

+5
source share

AddressEntry also has the SMTPAddress property, which provides the primary smtp address of the user.

+2
source share

try it

 private string GetSMTPAddressForRecipients(Recipient recip) { const string PR_SMTP_ADDRESS = "http://schemas.microsoft.com/mapi/proptag/0x39FE001E"; PropertyAccessor pa = recip.PropertyAccessor; string smtpAddress = pa.GetProperty(PR_SMTP_ADDRESS).ToString(); return smtpAddress; } 

It is available on MSDN here.

I used the same way to get email addresses in my application and its operation.

+2
source share

I do not know if this helps or how accurately

 it is, a sample private string GetSmtp(Outlook.MailItem item) { try { if (item == null || item.Recipients == null || item.Recipients[1] == null) return ""; var outlook = new Outlook.Application(); var session = outlook.GetNamespace("MAPI"); session.Logon("", "", false, false); var entryId = item.Recipients[1].EntryID; string address = session.GetAddressEntryFromID(entryId).GetExchangeUser().PrimarySmtpAddress; if (string.IsNullOrEmpty(address)) { var rec = item.Recipients[1]; var contact = rec.AddressEntry.GetExchangeUser(); if (contact != null) address = contact.PrimarySmtpAddress; } if (string.IsNullOrEmpty(address)) { var rec = item.Recipients[1]; var contact = rec.AddressEntry.GetContact(); if (contact != null) address = contact.Email1Address; } return address; } finally { } } 
0
source share

All Articles