2013-10-22 26 views
0

'Dashboard.Email'沒有包含'Application'的定義,也沒有包含接受'Dashboard.Email'類型的第一個參數的擴展方法'Application'可以找到(您是否缺少使用指令或程序集引用?)錯誤:'MyProject.Email不包含'應用程序'的定義

我試過添加引用和使用語句無濟於事。我只是想在VS2010 .NET 4 Framework中創建一個簡單的郵件對象。

using System; 
using System.Data; 
using System.Windows; 
using System.Linq; 
using System.Text; 
using System.Windows.Forms; 
using System.ComponentModel; 
using System.Threading.Tasks; 
using System.Collections.Generic; 
using System.Deployment.Application; 
using System.Runtime.InteropServices; 
using Microsoft.Office.Interop.Outlook; 

namespace Dashboard 
{ 
    public class Email 
    { 
     public void CreateEmailItem() 
     { 
      MailItem eMail = (MailItem)this.Application.CreateItem(OlItemType.olMailItem); 

      eMail.Subject = "This is the subject"; 
      eMail.To = "[email protected]"; 
      eMail.Body = "This is the body"; 
      eMail.Importance = OlImportance.olImportanceLow; 

      ((_MailItem)eMail).Send(); 
     } 
    } 
} 
+0

您可以參考的答案該鏈接 http://stackoverflow.com/questions/11242745/trying-to-programmatically-create-open-a-new-outlook-email – dmn

回答

1

這裏是指當前的類是電子郵件類。它沒有定義應用程序屬性定義。因此錯誤。

看起來您正在嘗試使用Outlook interop創建MailItem。

更換

MailItem eMail = (MailItem)this.Application.CreateItem(OlItemType.olMailItem); 

MailItem eMail = (MailItem)Application.CreateItem(Outlook.OlItemType.olMailItem); 

您的代碼,否則看起來好像沒什麼問題,但Codesnippet在MSDN上http://msdn.microsoft.com/en-us/library/bb644320%28v=office.14%29.aspx文章可能會給你一個好主意。

相關問題