1

I am writing simple Outlook program in C# which records MailItem’s Recipients for sent mail. To build that I am hooking into Outlook Mailitem Send event to get Recipient collection. Also to avoid Outlook security prompt I am using Redemption SafeMailItem.

For reading Recipient collection I am assigning MailItem to SafeMailItem and read Recipients. However Recipient collection won’t be same if MailItem has unsaved changes. In order to copy Recipient collection, MailItem requires to be saved and then access via Redemption SafeMailItem.

Here is example.

//event handler
void _MailItemSend(ref bool Cancel)
{
    SafeMailItem safeMailItem = (SafeMailItem)Activator.CreateInstance(Type.GetTypeFromProgID(RDOCustomClasses.SafeMailItem));
    SafeRecipients recipients = null;

    safeMailItem.Item = mailItem; // Assigning original mailItem which getting sent by outlook without saving it (just compose & send email before it get autosaved by outlook or manually)
    recipients = safeMailItem.Recipients

    // If mailItem have unsaved changes safeMailItem.Recipients will be different. 
    recipients.Count != mailItem.Recipients.Count;
}

So I believe calling Save() makes sense but I am not changing anything and calling Save() is causing another issue. When I try to quit Outlook it says:

there are unsaved changes “ do you want to save change”.

I tried accessing directly Mailitem.Recipients (it has latest and unsaved recipient list before mail getting send) but it creates Outlook security prompt. If I used Redemption it requires call to save before accessing it which creates other issue.

Is there a better way to receive Outlook Sent Mail Recipients in safe manner without modification ? Your suggestion will be appreciated.

4

0 回答 0