【发布时间】:2014-11-28 03:32:30
【问题描述】:
我目前正在改进一个 MS Outlook 加载项,以提取最终在垃圾文件夹中带有“合法”地址的电子邮件,然后将它们移动到收件箱文件夹中。
这种情况在 Gmail 地址中经常发生,对于我们的工作人员来说有点麻烦,他们必须手动将这些电子邮件链接到他们的客户帐户。
有人尝试过吗?我已注册传入电子邮件事件处理程序以在收到电子邮件时读取垃圾文件夹,但我不断收到异常。我怀疑这与其中一些电子邮件是垃圾邮件有关。这仅仅意味着 MailItem 会有很多错误。
有人遇到过同样的问题吗?这是我的代码:
public void OutlookApplication_ItemReceived(string entryID)
{
//this.outlookNameSpace = this.application.GetNamespace("MAPI");
//Outlook.MAPIFolder inbox = this.outlookNameSpace.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderInbox);
//Outlook.MAPIFolder junkFolder = this.outlookNameSpace.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderJunk);
if (Properties.Settings.Default.AutoLink || Properties.Settings.Default.EnableLeadLoader)
{
Outlook.MailItem mail = null;
try
{
this.Log("Email detected: incoming");
mail = this.application.Session.GetItemFromID(entryID) as Outlook.MailItem;
this.leadLoaderRecipient = Properties.Settings.Default.LeadLoaderRecipient.ToLower();
Outlook.Recipients recips = mail.Recipients; //That's where its crashing as the object is null... if read from spam folder
foreach (Outlook.Recipient recip in recips)
{
Outlook.PropertyAccessor pa = recip.PropertyAccessor;
string smtpAddress = pa.GetProperty(PR_SMTP_ADDRESS).ToString();
if (Properties.Settings.Default.EnableLeadLoader)
{
if (smtpAddress.ToLower() == this.leadLoaderRecipient)
this.ProcessLead(mail);
}
}
if (Properties.Settings.Default.AutoLink)
{
this.AutoLink(mail, true);
}
}
catch (Exception ex)
{
this.Log("Exception (ItemReceived): " + ex.ToString());
}
finally
{
if (mail != null)
{
Marshal.ReleaseComObject(mail);
}
}
}
}
期待你们的想法! :) TIA!
【问题讨论】:
标签: c# office-interop outlook-addin outlook-2010 mapi