Reputation: 401
Based on this issue, I can save an Outlook.Mailitem object as a file when it is being sent:
..
using Outlook = Microsoft.Office.Interop.Outlook;
...
public partial class MyClass: DevExpress.XtraEditors.XtraUserControl
{
static Microsoft.Office.Interop.Outlook.MailItem mailItem;
...
public static void SendAnOutlookMail()
{
...
mailItem.Display(false);
((Outlook.ItemEvents_10_Event)mailItem).Send += new Microsoft.Office.Interop.Outlook.ItemEvents_10_SendEventHandler(ThisAddIn_Send);
...
};
static void ThisAddIn_Send(ref bool Cancel)
{
mailItem.SaveAs(@"d:\1\sent.msg");
}
...
}
My only problem is that the resulting file is an email in its state just before it has been sent (when I open it, I can press the send button on it).
My question: How could I save it in the sent state?
Upvotes: 0
Views: 1276
Reputation: 66235
the earliest you can access the item in its sent state and the sender information populated is in the Items.ItemAdd
event handler on the Sent Items folder.
Upvotes: 2