2014-10-27 58 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

相关问题