2014-10-27 74 views
1

我想編寫和電子郵件並使用c#打開Outlook 2013的撰寫窗口。以下是我的代碼。它不顯示任何錯誤,但沒有窗口打開!有沒有人有什麼可能是問題的一個想法:使用C#編寫使用outlook 2013的電子郵件#

   Microsoft.Office.Interop.Outlook.Application app = new Microsoft.Office.Interop.Outlook.Application(); 
       Microsoft.Office.Interop.Outlook.MailItem mailItem = app.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem); 
       mailItem.Subject = "This is the subject"; 
       mailItem.To = "[email protected]"; 
       mailItem.Body = "This is the message."; 
       //mailItem.Attachments.Add(logPath);//logPath is a string holding path to the log.txt file 
       mailItem.Display(false); 

回答

2

你非常接近,你只需要設置mailItem.Display(true)下面的工作對我來說:

Microsoft.Office.Interop.Outlook.Application app = new Microsoft.Office.Interop.Outlook.Application(); 
       Microsoft.Office.Interop.Outlook.MailItem mailItem = app.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem); 
       mailItem.Subject = "This is the subject"; 
       mailItem.To = "[email protected]"; 
       mailItem.Body = "This is the message."; 
       //mailItem.Attachments.Add(logPath);//logPath is a string holding path to the log.txt file 
       mailItem.Display(true) //THIS IS THE CHANGE; 
+0

是的,其實我試過了,但它沒有在我的系統上工作,因爲它有問題,需要重新啓動。謝謝。 – NESHOM 2014-10-27 03:02:05

相關問題