2014-06-14 56 views
1

我想向我的電子郵件正文添加一些文本。但我不斷收到此錯誤:使用Outlook插件將文本添加到電子郵件C#2010

Error 1 'EmailHelper.EmailHelperRibbon' does not contain a definition for 'Application' and no extension method 'Application' accepting a first argument of type 'EmailHelper.EmailHelperRibbon' could be found (are you missing a using directive or an assembly reference?)

我的代碼如下所示:

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using Microsoft.Office.Tools.Ribbon; 
using System.Windows.Forms; 

namespace EmailHelper 
{ 
    public partial class EmailHelperRibbon 
    { 
     private void EmailHelperRibbon_Load(object sender, RibbonUIEventArgs e) 
     { 

     } 

     private void button1_Click(object sender, RibbonControlEventArgs e) 
     { 
      System.Windows.Forms.MessageBox.Show("Your Ribbon Works!"); 
      Microsoft.Office.Interop.Outlook.MailItem mailItem = (Microsoft.Office.Interop.Outlook.MailItem) 
       this.Application.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem); 
      { 
       mailItem.Subject = "This text was added by using code"; 
       mailItem.Body = "This text was added by using code"; 
      } 

     } 
    } 
} 

回答

1

我猜這是基於名稱的功能區,所以你需要訪問應用程序關閉Globals的類:

Globals.ThisAddIn.Application.CreateItem(...) 
+0

讓我過去的錯誤,但它不會將文本添加到電子郵件的主題或正文。 – PriceCheaperton

1

試試這個:

var inspector = this.Context as Outlook.Inspector; 
var currentMailItem = inspector.CurrentItem as Outlook.MailItem; 
currentMailItem.Body = "your text"; 
相關問題