使用 C# 获取 header 信息
Getting header information using c#
我正在尝试在 C# 中创建一个 outlook add-in,它从收件箱中的新电子邮件中收集 header 信息。谷歌搜索说使用以下代码获取电子邮件的 header 信息。
mailitem.PropertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x007D001F/")
然而,当我使用它时,错误 Object 引用未设置为 object 的实例。单击架构地址还说该资源不再有其他获取方式,还是我需要使用其他语言?
为了参考,我添加了以下内容。
private void Quarantine()
{
Outlook.MAPIFolder inBox = (Outlook.MAPIFolder)this.Application.
ActiveExplorer().Session.GetDefaultFolder
(Outlook.OlDefaultFolders.olFolderInbox);
Outlook.Items items = (Outlook.Items)inBox.Items;
Outlook.MailItem MailItem = null;
items.Restrict("[UnRead] = true");
var destFolder = inBox.Folders["test"];
string StrRegex = @"(Final Score - [-][0-9] | Final Score - [2][0 - 1] | Final Score - [0 - 1][0-9])";
Regex Reg = new Regex(StrRegex);
foreach (object email in items)
{
MailItem = email as Outlook.MailItem;
String Header= MailItem.PropertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x007D001F/");
if (!(Reg.IsMatch(Header)))
{
MailItem.Move(destFolder);
}
}
}
}
as
运算符将 return null 是对象不是 MailItem
。您的代码从不检查它。收件箱文件夹中可以有 MailItem
以外的对象,例如 ReportItem
、MeetingItem
等
我正在尝试在 C# 中创建一个 outlook add-in,它从收件箱中的新电子邮件中收集 header 信息。谷歌搜索说使用以下代码获取电子邮件的 header 信息。
mailitem.PropertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x007D001F/")
然而,当我使用它时,错误 Object 引用未设置为 object 的实例。单击架构地址还说该资源不再有其他获取方式,还是我需要使用其他语言?
为了参考,我添加了以下内容。
private void Quarantine()
{
Outlook.MAPIFolder inBox = (Outlook.MAPIFolder)this.Application.
ActiveExplorer().Session.GetDefaultFolder
(Outlook.OlDefaultFolders.olFolderInbox);
Outlook.Items items = (Outlook.Items)inBox.Items;
Outlook.MailItem MailItem = null;
items.Restrict("[UnRead] = true");
var destFolder = inBox.Folders["test"];
string StrRegex = @"(Final Score - [-][0-9] | Final Score - [2][0 - 1] | Final Score - [0 - 1][0-9])";
Regex Reg = new Regex(StrRegex);
foreach (object email in items)
{
MailItem = email as Outlook.MailItem;
String Header= MailItem.PropertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x007D001F/");
if (!(Reg.IsMatch(Header)))
{
MailItem.Move(destFolder);
}
}
}
}
as
运算符将 return null 是对象不是 MailItem
。您的代码从不检查它。收件箱文件夹中可以有 MailItem
以外的对象,例如 ReportItem
、MeetingItem
等