在Outlook加载项中发送后保存电子邮件 [英] Save Email Upon Send in Outlook Add-In

查看:82
本文介绍了在Outlook加载项中发送后保存电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作一个Outlook加载项(Visual Studio 2010,.NET 4.0,C#),我希望在用户发送电子邮件后自动将其存档.到目前为止,我有以下内容:

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)
{
}

通过调试发现,我的saveEmail方法在电子邮件实际发送之前就触发了.没关系,理想情况下,我希望在成功发送电子邮件后立即将其关闭,因此,如果有办法做到这一点,我将感谢一些提示.

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.

无论如何,我都可以进入该方法,而我想做的就是以Outlook.MailItem对象的形式访问该电子邮件,并使用.SaveAs方法和我选择的任何参数.我该如何抓取当前打开并即将发送的电子邮件作为MailItem对象?

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?

推荐答案

您可以尝试使用此代码

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

这篇关于在Outlook加载项中发送后保存电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆