问题
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