How to change email body format to HTML from an Outlook VSTO add-in?

1.5k Views Asked by At

I'm coding an Outlook add-in, that is written using Visual Studio and VSTO, that can automatically change the format of outbound emails to HTML:

enter image description here

I'd doing the following:

private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
    //Add event handler for when emails are sent out
    this.Application.ItemSend += new Microsoft.Office.Interop.Outlook.ApplicationEvents_11_ItemSendEventHandler(onItemSend);
}

private void onItemSend(object Item, ref bool Cancel)
{
    //Called when email is sent
    Outlook.MailItem objMailItem = (Outlook.MailItem)Item;

    //Set message format as HTML
    objMailItem.BodyFormat = Microsoft.Office.Interop.Outlook.OlBodyFormat.olFormatHTML;
}

I'm noticing that my onItemSend is called, and if the original email that is being sent was composed as plain-text, that email still arives at the destination as plain-text in despite of my change there. I even tried reading objMailItem.BodyFormat back and it says olFormatHTML.

What am I doing wrong?

1

There are 1 best solutions below

0
Eugene Astafiev On

In addition to setting the BodyFormat property, you need to set the correct HTML markup for your message body - the HTMLBody property sets a string representing the HTML body of the specified item. Setting the HTMLBody property will always update the Body property immediately.