Get email address from MailItem.To?

M

Mark B

VSTO OL2007 C#

When I am sending an email, how do I extract the email address component
from the TO field?

MailItem.Recipients field doesn't have any objects in the list before
Outlook sends an item. MailItem.To just has address book names and not email
addresses.
 
K

Ken Slovak - [MVP - Outlook]

Trap the item.Send() event and in that event save the item then read the
recipient properties you want.
 
M

Mark B

Please excuse any newbie ignorance on this but I put a breakpoint after the
following code to see what mail.Recipients would expose for me in the
immediate window:

Outlook.MailItem mail1 = Item as Outlook.MailItem;
mail1.Save();

I could get mail1.Recipients.Count to return me 1. I thought
mail1.Recipients(1).emailaddress or similar would return me the raw email
address of the first recipient but I couldn't see that type of thing.

What code would I need to return me the email address?
 
M

Mark B

"Error 7 'Microsoft.Office.Interop.Outlook.Recipients' does not contain a
definition for 'Item' and no extension method 'Item' accepting a first
argument of type 'Microsoft.Office.Interop.Outlook.Recipients' could be
found (are you missing a using directive or an assembly reference?)"
 
M

Mark B

Thanks Ken, that works.

Ken Slovak - said:
In C# it would be mail1.Recipients[1].




Mark B said:
"Error 7 'Microsoft.Office.Interop.Outlook.Recipients' does not contain a
definition for 'Item' and no extension method 'Item' accepting a first
argument of type 'Microsoft.Office.Interop.Outlook.Recipients' could be
found (are you missing a using directive or an assembly reference?)"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top