2014-10-03 47 views
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!

回答

0

當究竟你的代碼運行?那是一個Application.NewMailEx事件處理程序嗎?什麼是例外?

嘗試在垃圾郵件文件夾上使用Items.ItemAdd事件而不是使用Application.NewMailEx。

+0

嗨@dmitry,這是目前正在我實施的控制器中執行,它運行我的OutlookApplication_ItemReceived事件處理程序。我得到的例外是我的MailItem作爲空對象返回。郵件發送到收件箱時不會發生這種情況。 – cmnunis 2014-10-06 23:38:10

+0

您是否嘗試過垃圾郵件文件夾上的Items.ItemAdd事件? – 2014-10-07 14:02:17

相關問題