2015-04-24 97 views
0

我試圖通過C#代碼插件自定義Outlook。它正在工作,但是當打開兩封或更多封郵件(通過新郵件)時,會出現一些問題。所以我想避免在Outlook中同時打開兩個或更多的撰寫郵件。我的Outlook版本是2013.如何在Outlook中一次避免兩個撰寫郵件

在下面的代碼中,我嘗試在發送點擊事件時發送附加文件的鏈接。如果這個人在同一時間打開兩個或更多的撰寫郵件,這將會崩潰(我在我的項目中寫了很多代碼來獲取附加代碼和其他鏈接)。我怎樣才能避免兩個撰寫郵件或爲兩個撰寫郵件對話維護不同的會話?

void Application_ItemSend(object Item, ref bool Cancel) 
{ 
    int attachcountbs=0; 
    StringBuilder sendinglink = new StringBuilder(); 
    string[] comingstrbuilder = Convert.ToString(SPForm.urlofattach).Split('\n'); 
    Outlook.Application oApp = new Outlook.Application(); 
    Outlook.MailItem oMsg = (Outlook.MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem);   
    StringBuilder sb = new StringBuilder(); 

    //sb.AppendLine("-------------Internal Use-------------<br/>"); 
    //sb.AppendLine("<a href='" + Class1.test + "'>" + Class1.test + "</a>"); 

    if (Item is Outlook.MailItem) 
    { 
     Outlook.MailItem mail = (Outlook.MailItem)Item; 
     Outlook.NameSpace session = mail.Session; 
     attachcountbs = mail.Attachments.Count; 

     int arraycount = comingstrbuilder.Count(); 
     int checkattach=1; 
     for (int i = 0; i < arraycount; i++) 
     { 
      if (attachcountbs < checkattach) 
      { 
       break; 
      } 
      if (comingstrbuilder[i].Contains(mail.Attachments[checkattach].DisplayName)) 
      { 

      //} 
      //if (comingstrbuilder[i] == mail.Attachments[checkattach].DisplayName) 
      //{ 
       sendinglink.AppendLine(comingstrbuilder[i]); 
       checkattach++; 
      } 
     } 

     if (mail.Attachments.Count == 0) 
     { 
      mail.HTMLBody = ""; 
     } 
     else 
     { 
      mail.HTMLBody += "-------------Internal Use-------------<br/>"; 

      //mail.HTMLBody += "<a href='" + Class1.test + "'>" + Class1.test + "</a>"; 
      //mail.HTMLBody += SPForm.urlofattach.ToString(); 
      mail.HTMLBody += sendinglink.ToString(); 
      SPForm.urlofattach.Clear(); 
     } 
    } 
} 
+2

試圖阻止用戶以他們想要的方式使用Outlook,似乎是... *錯誤* ...解決方案。我建議更側重於讓你的代碼優雅地處理這種情況。 –

+0

比你.....我得到了一些其他的邏輯與我的代碼來處理更多的新郵件窗口........ – RSB

回答

0

我注意到下面的代碼:

Outlook.Application oApp = new Outlook.Application(); 

沒有必要在ItemSend事件處理程序,以創建新的Outlook應用實例。相反,您需要使用加載項類的Application屬性。

Display方法接受一個允許顯示模態窗口的布爾參數。在這種情況下,用戶應該在打開另一個檢查員窗口之前關閉這些窗口。只要通過這個方法。

此外,單個Outlook實例可以在同一時間,因此只能有一個會話。

相關問題