Minty

I'm creating an addin for Outlook 2003 using VSTO in VS.NET 2.0. I'm trying to get all the email addresses in the To filed by

private void ThisApplication_ItemSend(object Item, ref bool Cancel)

{

MailItem mail = (MailItem)Item;

string allEmailAddress = mail.To;

}

However, the mail.To doesn't return the full email address in the format of john.doe@domain.com. Rather, it returns Doe, John if I already sent emails to this person before.

Can someone help me out and show me how to get the full email addres instead of the person's name

Thank you!!!



Re: Visual Studio Tools for Office Outlook - how to get full emailaddress from To filed in Outlook

Sue Mosher - Outlook MVP

Work with the MailItem's Recipients collection. Each Recipient object has an Address property and a Type property that will tell you whether it's a To, Cc, or Bcc.





Re: Visual Studio Tools for Office Outlook - how to get full emailaddress from To filed in Outlook

Minty

Sue,

Thank you very much for your help! The Address property works out great for external email address. But for internal email address, the property returns as xml string /o=company/ou=americas01/cn=recipients/cn=userid. I wonder if I could make the assumption that if an email address contains "@", it' an external one. Else it'll be internal.

Thank you,

Jenny





Re: Visual Studio Tools for Office Outlook - how to get full emailaddress from To filed in Outlook

Sue Mosher - Outlook MVP

The Recipient.AddressEntry.Type property will tell you whether it's an SMTP address or an Exchange (EX) address. Exchange addresses are always in X.400 format. If you want the SMTP address for an Exchange user, you need to use Outlook 2007, Redemption, MAPI33, Extended MAPI, or CDO 1.21, the last two not being supported directly in .NET languages. See http://www.outlookcode.com/codedetail.aspx id=1112, though, for a MAPI sample.

See http://www.outlookcode.com/d/code/getsenderaddy.htm#redemption and http://www.cdolive.com/cdo5.htm#EMailAddressOfSender for Redemption and CDO examples and http://groups.google.com/group/microsoft.public.outlook.program_vba/browse_frm/thread/4d4d5fece24a2a7/ad2fcbb691d5bf18 for a discussion of the property to use with Cached Exchange Mode in Outlook 2003 or later.






Re: Visual Studio Tools for Office Outlook - how to get full emailaddress from To filed in Outlook

Minty

Sue,

Your answer was exactly what I was looking for.

I am also trying to create a folder under Exchange server (not personal folder) in outlook. But I was only able to get a list of root folders by

Outlook.MAPIFolder root = (Outlook.MAPIFolder)_nameSpace.GetDefaultFolder(OlDefaultFolders.olFolderInbox).Parent;

Could you give me some suggestion on how to add a new folder

Thank you for your advice!





Re: Visual Studio Tools for Office Outlook - how to get full emailaddress from To filed in Outlook

Sue Mosher - Outlook MVP

Each MAPIFolder in the Namespace.Folders collection is the root of an information store (Exchange mailbox, .pst file, Public Folders hierarchy, etc.). Each MAPIFolder in turn has its own Folders collection, and each MAPIFolder in a Folders collection has a unique name. Therefore, you can to walk down the folder hierarchy, getting the desired folder at each level, until you arrive at the folder where you want to create the new subfolder using the MAPIFolder.Folders.Add method. See http://support.microsoft.com/ kbid=310244





Re: Visual Studio Tools for Office Outlook - how to get full emailaddress from To filed in Outlook

Minty

Sue,

Your answer helped me again! Smile

After creating the folder, I found that the folder doesn't have enough permission for me to move an item to it. I googled for a while and found an article you post on a forum, which talked about how to find out the code for the COMException. The exception I'm getting is as following. How should I grant my application the right permission on the folder so that I can move the email to the folder that just created by the application

Case -2147467260 ' User responded NO to security prompt
MessageBox.Show("It won't work unless you say Yes to the security prompt.")


Thank you again for your prompt response!





Re: Visual Studio Tools for Office Outlook - how to get full emailaddress from To filed in Outlook

Sue Mosher - Outlook MVP

I presume you've already tested to see whether you can create a new item in that folder manually The owner of the folder would have to grant that permission. It's not something your application can do if the current user isn't the owner (in which case they'd already have the necessary permission).