我使用C和Visual Studio 2008编写了这个小的MS Outlook 2003 VSTO加载项。它的作用是检查每一个发送邮件的正文中是否有单词“attach”,如果找到,则检查附件的数量。如果这个数字是零,那么询问用户他们是否真的打算发送消息。它应该像Gmail实验室的功能一样工作,做同样的事情。
奇怪的是,它可以工作,但是第一次运行它时,我会暂停一下,就像邮件窗口被挂起了大约45秒。一旦它过去,它运行非常快的剩余时间,我有展望打开。但是,如果我关闭了Outlook,那么下次重新打开它并发送消息时,我将再次等待。
有什么想法吗,人民?
这是我的外接程序的代码:
namespace OutlookAttacher
{
public partial class ThisAddIn
{
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
this.Application.ItemSend += new Outlook.ApplicationEvents_11_ItemSendEventHandler(Application_ItemSend);
}
private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
{
}
void Application_ItemSend(object Item, ref bool Cancel)
{
if (Item is Microsoft.Office.Interop.Outlook.MailItem)
{
Microsoft.Office.Interop.Outlook.MailItem currentItem = Item as Microsoft.Office.Interop.Outlook.MailItem;
Cancel = true;
if (currentItem.Body.Contains("attach"))
{
if (currentItem.Attachments.Count > 0)
{
Cancel = false;
//MessageBox.Show("This message will be sent now.");
currentItem.Send();
}
else
{
DialogResult ans = MessageBox.Show("This message has no attachments. Are you sure you want to send it?", "OutlookAttacher", MessageBoxButtons.YesNo);
if (ans.Equals(DialogResult.Yes))
{
Cancel = false;
//MessageBox.Show("This message will be sent now.");
currentItem.Send();
}
}
}
else
{
Cancel = false;
//MessageBox.Show("This message will be sent now.");
currentItem.Send();
}
}
}
}
}
任何改进代码的建议都是受欢迎的,因为这是我第一次尝试使用Outlook外接程序。
更新:
我在一台5年的戴尔笔记本电脑上运行这个程序,2 GB的RAM和我不知道哪个Intel CPU。我喜欢添加跟踪/调试它的想法。我将要去找出如何逐步通过代码,以便我可以看到它可能需要最长的时间。谢谢大家!