2

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?

Jake
  • 3,142
  • 4
  • 30
  • 48
  • 1
    This way, the saved email will be showing as un-send email. A better way is to handle `ItemAdd` event of the Sent Mail folder, and save the mail actually got saved there. – Bolu Oct 30 '13 at 12:03

1 Answers1

3

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);
}
cjk
  • 45,739
  • 9
  • 81
  • 112
Aghilas Yakoub
  • 28,516
  • 5
  • 46
  • 51