Set a MailItem as sent before calling SaveAs in Outlook Addin with C#

戏子无情 提交于 2019-12-23 02:46:20

问题


I am building an Outlook 2010 addin to integrate it with some business software and have trapped the ItemSend Event. I check if it is a MailItem and if it is I call the SaveAs function to save it as a .msg to the file system (in the users temp folder).

void Application_ItemSend(object Item, ref bool Cancel)
{
    if(Item is Outlook.MailItem)
    {
        Outlook.MailItem mailitem = (Outlook.MailItem)Item;
        string filename = "somefilename.msg";
        string path = System.IO.Path.GetTempPath();
        string fullPathName = path+filename;
        mailitem.SaveAs(fullPathName, Outlook.OlSaveAsType.olMSG);
    }
}

I go on to read the file contents and send the file to the server using webservices. It all works fine.

The issue I have is if I go and open the file that it saves, then Outlook opens it as a message still being composed and the user could very easily click the Send button again.

Is there a way to flag that the item has been sent before it gets saved so when opened after the fact it opens as a readable email rather than an in-composition email?


回答1:


Take a look at this post (and additionally at the last answer on that page), this might help you.

(Makes use of ItemAdd event)



来源:https://stackoverflow.com/questions/8799622/set-a-mailitem-as-sent-before-calling-saveas-in-outlook-addin-with-c-sharp

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