我刚刚开始为Outlook开发一个Addin。当我第一次运行Addin Outlook打开时,外接程序的安装窗口就会显示,它可以正常工作。例如,我的测试应用程序将主题为“二手车”的电子邮件移动到回收站。
我将过滤器改为“测试”,在VS2010中运行调试器,并给自己发了一封带有“测试”的电子邮件。由于某种原因,它不起作用。然而,尽管我已经更改了代码,但它仍然在移动带有“二手车”主题的电子邮件。
我已经尝试从Outlook中删除Addin,这没有帮助。
以下是当前代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using Outlook = Microsoft.Office.Interop.Outlook;
using Office = Microsoft.Office.Core;
namespace test3
{
public partial class ThisAddIn
{
Outlook.NameSpace outlookNameSpace;
Outlook.MAPIFolder inbox;
Outlook.Items items;
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
outlookNameSpace = this.Application.GetNamespace("MAPI");
inbox = outlookNameSpace.GetDefaultFolder(
Microsoft.Office.Interop.Outlook.
OlDefaultFolders.olFolderInbox);
items = inbox.Items;
items.ItemAdd +=
new Outlook.ItemsEvents_ItemAddEventHandler(items_ItemAdd);
}
void items_ItemAdd(object Item)
{
string filter = "test";
Outlook.MailItem mail = (Outlook.MailItem)Item;
if (Item != null)
{
if (mail.MessageClass == "IPM.Note" &&
mail.Subject.ToUpper().Contains(filter.ToUpper()))
{
mail.Move(outlookNameSpace.GetDefaultFolder(
Microsoft.Office.Interop.Outlook.
OlDefaultFolders.olFolderDeletedItems));
}
}
}
private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
{
}
#region VSTO generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InternalStartup()
{
this.Startup += new System.EventHandler(ThisAddIn_Startup);
this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown);
}
#endregion
}
}原始代码可以找到这里。
目前,我唯一的解决方案是在每次更改代码时创建一个具有不同名称的新项目。
谢谢你的帮助!
更新
我已经购买了一台新的PC,作为工作升级的一部分,以及Visual和Outlook的最新版本。这已经不再是一个问题了。
发布于 2016-02-19 11:33:36
您的问题可能与Visual的版本有关。我刚刚在VS2013中尝试过这一点,没有任何问题。在我看来你的代码很好。
https://stackoverflow.com/questions/35503877
复制相似问题