Reputation: 807
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.
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).
Upvotes: 1
Views: 1522
Reputation: 1
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.
Upvotes: 0
Reputation: 31
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.
Upvotes: 3
Reputation: 49395
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.
Upvotes: 0