2013-03-24 76 views
-1

我需要從SharePoint打開Outlook郵件compaose編程,我想這代碼,但它只是打開Outlook的過程,但在撰寫郵件窗口沒有出現如何從2010年的SharePoint打開Outlook撰寫新郵件progamaticallly

using (SPSite currentSite = new SPSite(SPContext.Current.Site.ID)) 
      { 
       using (SPWeb currentWeb = currentSite.OpenWeb(SPContext.Current.Web.ID)) 
       { 
        WebURL = currentWeb.Url; 
        currentWeb.AllowUnsafeUpdates = true; 
        SPList correspondences = currentWeb.Lists.TryGetList("list1"); 

        SPListItem correspondenceItem = correspondences.GetItemById(id); 
        WebURL = currentWeb.Url; 
        SPAttachmentCollection CorrespondenceAttachemt = correspondenceItem.Attachments; 

              Microsoft.Office.Interop.Outlook.Application oApp = new Microsoft.Office.Interop.Outlook.Application(); 
        Microsoft.Office.Interop.Outlook._MailItem oMailItem = (Microsoft.Office.Interop.Outlook._MailItem)oApp.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem); 

        oMailItem.Body = body; 
        oMailItem.Subject = title; 



        oMailItem.Display(); 

       } 
      } 
+0

你可能會在'oMailItem.Display();'上得到一個異常。嘗試在代碼上附加斷點 – 2013-03-27 11:00:00

+0

是的......錯誤是「Microsoft Exchange不可用,或者存在網絡問題或Exchange服務器因維護而關閉。」 – mahamed 2013-03-28 12:24:48

回答

1

該代碼正在SharePoint服務器上運行,對嗎?在這種情況下,您將在服務器端啓動Outlook,而不是客戶端。除此之外,Outlook(就像任何其他Office應用程序一樣)不能用於服務。

爲什麼不使用mailto url?

+0

好吧,我怎麼可以打開它在客戶端 – mahamed 2013-03-25 07:46:50

+0

我沒有使用mailto網址,因爲我想添加附件在這個撰寫郵件從一個項目在SharePoint列表中,我也想填寫主題 – mahamed 2013-03-25 08:18:02

+0

它似乎是在配置問題在共享點,因爲我在控制檯應用程序中嘗試此代碼它打開Outlook撰寫郵件 – mahamed 2013-03-25 10:28:20

0

默認情況下oMailItem.Display爲False。將其更改爲true。

oMailItem.Display (true); 

這應該現在工作。

+0

是否與你一起工作? ,我已經嘗試過,但仍然無法正常工作,OUTLOOK程序已經在任務管理器中打開,但是Outlook的撰寫郵件窗口不是,請注意,我在控制檯應用程序中嘗試了我的代碼,它工作正常 – mahamed 2013-03-28 09:31:41

+0

它爲我工作。 – 2013-03-28 12:03:18

+0

是否在Display()方法中添加了'true'參數? – 2013-03-28 12:03:53

相關問題