0
votes

I am sending emails using VBA with Outlook (Office 365), based on an HTML formatted template (.oft). It's somewhat heavy due to some images (2Mb total)
Many times it works fine.
Sometimes it loses the HTML formatting, and sends a plain text email (same recipient, same template, same sender, same hardware / software).

Two things I tried.

  1. Slow down the loading of template (application.wait)
  2. Setting the format explicitly as HTML
row = 2
Do While Sheets("invitees").Cells(row, 1) <> ""
    Email_Send_To = Sheets("invitees").Cells(row, 1)
    Set Mail_Single = Mail_Object.CreateItemFromTemplate("K:\Path\Product Update.oft")
    Application.Wait (Now + #12:00:04 AM#) 'didn't help
    
    With Mail_Single
        .To = Email_Send_To
        .SentOnBehalfOfName = Email_Send_From
        .Subject = "Product Update"
        .BodyFormat = olFormatHTML 'didn't help
        .Send
    End With
row = row + 1
Loop

I stripped the code down to

Set Mail_Single = Mail_Object.CreateItemFromTemplate("K:\Path\Product Update.oft")
MsgBox (Mail_Single.BodyFormat) 'the output is olFormatHTML as expected
Mail_Single.Close (olSave)

In the drafts, my email is consistently text only.

If I send the template manually, it goes as HTML (both Outlook and Gmail render it accurately).

3

3 Answers

0
votes

I'd suggest checking the list of running add-ins in Outlook. Add-ins may change the body format in the background (in any Outlook's event handler).

Set Mail_Single = Mail_Object.CreateItemFromTemplate("K:\Path\Product Update.oft")
Application.Wait (Now + #12:00:04 AM#) 'didn't help

Also, there is no need to add a delay right after the CreateItemFromTemplate call.

0
votes

Try this just before .Send:

.BodyFormat = olFormatHTML 'Probably it will work anyway, but just to be sure.
.HTMLBody = .HTMLBody 'A stupid assignment, but it works for me.
0
votes

Rebuild your template using Office 365 Design Forms and going to the Developer tab in Outlook.
Just call up your existing .oft then modify something trivial, and save it.