Why is email body, using custom template, delivered in plain text?

僤鯓⒐⒋嵵緔 提交于 2021-02-19 09:25:55

问题


I have a list of users to send multiple attachments with custom email body (.oft template).

User's details are in an Excel file.

I had prepared (.oft template) in standard format with some images and style fonts.

When I use msg.Send emails are delivered with an attachment but the email body is displayed in plain text. But, msg.Display displays the email with an associated attachment and expected email body (.oft template).

Option Explicit
Sub Send_Mails()
Dim sh As Worksheet
Set sh = ThisWorkbook.Sheets("Send_Mails")
Dim i As Integer

Dim OA As Object
Dim msg As Object

Set OA = CreateObject("outlook.application")
OA.Session.Logon

Dim last_row As Integer
last_row = Application.CountA(sh.Range("A:A"))

For i = 2 To last_row
    Set msg = OA.CreateItem(0)
    Set msg = OA.CreateItemFromTemplate("C:\Users\Test 2\Test.oft")
    msg.To = sh.Range("A" & i).Value
    msg.cc = sh.Range("B" & i).Value
    msg.Subject = sh.Range("C" & i).Value
    
    If sh.Range("E" & i).Value <> "" Then
        msg.Attachments.Add sh.Range("E" & i).Value
    End If

    msg.Display
    sh.Range("F" & i).Value = "Sent"
Next i

MsgBox "All the mails sent successfully"

End Sub

回答1:


If this delivers mail in correct format

msg.Display
msg.send

try

msg.GetInspector
msg.send

That way you do not see the flash that comes with .Display.



来源:https://stackoverflow.com/questions/64578477/why-is-email-body-using-custom-template-delivered-in-plain-text

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!