Save Email Upon Send in Outlook Add-In

别等时光非礼了梦想. 提交于 2019-12-04 04:53:23

问题


I'm making an Outlook Add-in (Visual Studio 2010, .NET 4.0, C#), and I would like to automatically archive a user's email after they send it. What I have so far is the following:

private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
   //Create an event handler for when items are sent
   Application.ItemSend += new ApplicationEvents_11_ItemSendEventHandler(saveEmail);
}


private void saveEmail(object Item, ref bool Cancel)
{
}

What I've found through debugging is that my saveEmail method fires off right before the email actually sends. This is OK, ideally I would like it to be fired off immediately after the email is sent successfully, so if there's a way to do that I'd appreciate some pointers.

In any case, I can get inside that method and what I'd like to do is access that email as an Outlook.MailItem object and use the .SaveAs method with whatever parameters I choose. How would I go about grabbing the currently-opened-and-about-to-be-sent-email as a MailItem object?


回答1:


you can try with this code

private void saveEmail(object Item, ref bool Cancel)
{
         var msg = Item as Outlook.MailItem;
         msg.SaveAs(yourPath, Outlook.OlSaveAsType.olMSG);
}


来源:https://stackoverflow.com/questions/12040239/save-email-upon-send-in-outlook-add-in

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!