4
votes

I read from Outlook Contacts my Contacts and then I add the Contact to MailMessage mail.To.Add("John Doe <John Doe>") but I receive this error:

The specified string is not in the form required for an e-mail address.

How can I resolve this? when I read from Outlook Contacts the result for email address is a long string like this (only for Exchange account types) and I prse to get the last cn= value: /o=First Organization/ou=Exchange Administrative Group (FYDIBOHF23SPDLT)/cn=Recipients/cn=John Doe

How can I read the correct e-mail address from an Exchange Account ([email protected]) or other method to send e-mail?

1

1 Answers

3
votes

If you have an ExchangeUser, you can access the property PrimarySmtpAddress for the Exchange email. Then the following should work for you...

MailMessage mail = new MailMessage();
mail.To.Add(exchangeUser.PrimarySmtpAddress);