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

查看:33
本文介绍了在 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天全站免登陆