1

I want to add some text to the body of my email. But i keep getting this error:

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?)

My code looks like this:

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";
            }

        }
    }
}
Soner Gönül
  • 97,193
  • 102
  • 206
  • 364
PriceCheaperton
  • 5,071
  • 17
  • 52
  • 94

2 Answers2

2

Try this one:

var inspector = this.Context as Outlook.Inspector;
var currentMailItem = inspector.CurrentItem as Outlook.MailItem;
currentMailItem.Body = "your text";
Osama
  • 154
  • 10
1

I am guessing this is a Ribbon based on the name, so you need to access the application off of the Globals class:

Globals.ThisAddIn.Application.CreateItem(...)
John Koerner
  • 37,428
  • 8
  • 84
  • 134