简体   繁体   中英

Get Recipients from Outlook.MailItem

I have an Outlook addin where I'm trying to get the email addresses when composing an email. When typing the addresses in the "To" field, if they are underlined then the addin reads all recipients properly. However if it's a new email address, ie. it won't be underlined, then that email address is not present in the Recipients list, here's my code:

Microsoft.Office.Interop.Outlook.MailItem email = GetMailItem(e);
int count = email.Recipients.Count;

首先做email.Save()

i think you should use the recipients.resolveall method - see https://msdn.microsoft.com/en-us/library/office/ff867165.aspx

Max

Strangly I have found that, while calling MailItem.Save() does resolve the Addresses (so that they are present in the MailItem.Recipients collection), calling MailItem.Save() more than once (3-4 times) risks the following exception:"System.Runtime.InteropServices.COMException (0x80040109): The operation cannot be performed because the message has been changed"

Getting the MailItem.HTMLBody property seems to resolve all valid the email addresses in the To, CC, BCC fields and avoid the risk of calling MailItem.Save() more than once.

I have personally found that MailItem.ResolveAll() simply clears any unresolved new Recipients added after the MailItem.Save() was last called.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM