0
我目前炼化的MS Outlook加载回暖,在以“合法”的地址的垃圾邮件文件夹最终的电子邮件,然后将它们移动到收件箱文件夹。以编程方式将项目从垃圾邮件文件夹移动到Outlook.Interop类中的收件箱?
这是发生了很多的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!
嗨@dmitry,这是目前正在我实施的控制器中执行,它运行我的OutlookApplication_ItemReceived事件处理程序。我得到的例外是我的MailItem作为空对象返回。邮件发送到收件箱时不会发生这种情况。 – cmnunis 2014-10-06 23:38:10
您是否尝试过垃圾邮件文件夹上的Items.ItemAdd事件? – 2014-10-07 14:02:17