Gmail Excel将图像添加为正文

thtygnil  于 2023-10-22  发布在  其他
关注(0)|答案(1)|浏览(109)

我目前正试图写一个自动化脚本,将发送出的电子邮件与图像在身体使用Gmail应用程序。下面是我的代码,我已经尝试,到目前为止,没有图像已显示在电子邮件正文。我只能添加图像作为附件,而不是作为主体。

Sub email_CDO()

Dim month As String

Set wb = ThisWorkbook

For iRow = 2 To wb.Sheets("client_list").Range("A1").CurrentRegion.Rows.Count

Set iMsg = CreateObject("CDO.Message")
Set iConf = CreateObject("CDO.Configuration")

    iConf.Load -1    ' CDO Source Defaults
    Set Flds = iConf.Fields
    With Flds
    .Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True
    .Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
    .Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "[email protected]"
    .Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "foukxizyifqoshhu"
    .Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.gmail.com"
    .Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
    .Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 465
        .Update
    End With

    With iMsg
        Set .Configuration = iConf
        .To = wb.Sheets("client_list").Cells(iRow, 2).Value
        .CC = ""
        .BCC = ""
        .ReplyTo = "[email protected]"
        .From = "[email protected]"
        .Subject = "--" & " " & month & " " & page_name
    
        .HTMLBody = "Hello " & page_name & _
            "<br><br>--" & _
            "<br><br>--" & _
            "<br><br>--" & _
            "<img src='C:\Users\foodpanda\Desktop\Email\Storage\email.jpg'>" & _
            "<br><br><font size='1' font color='grey'>???????????????????????????.</font>"
        If .To <> "" Then
            .AddAttachment "C:\Users\Desktop\Email\Storage\example.jpg"
            .Send
        End If

    End With

Next iRow

Set iMsg = Nothing
Set iConf = Nothing
Set Flds = Nothing
   
MsgBox "All email have been sent!"

End Sub
slhcrj9b

slhcrj9b1#

试着改变那些线条

"<img src='C:\Users\foodpanda\Desktop\Email\Storage\email.jpg'>" & _
    "<br><br><font size='1' font color='grey'>???????????????????????????.</font>"
If .To <> "" Then
    .AddAttachment "C:\Users\Desktop\Email\Storage\example.jpg"
    .Send
End If

有了这些更新的台词,也许这会有所帮助

"<img src='cid:email.jpg'>" & _
  "<br><br><font size='1' font color='grey'>???????????????????????????.</font>"
 If .To <> "" Then
  Dim objBP As Object:  Set objBP = iMsg.AddRelatedBodyPart("C:\Users\foodpanda\Desktop\Email\Storage\email.jpg", "email.jpg", CdoReferenceTypeName)
    objBP.Fields.Item("urn:schemas:mailheader:Content-ID") = "<email.jpg>"
    objBP.Fields.update
.AddAttachment "C:\Users\foodpanda\Desktop\Email\Storage\email.jpg"
.AddAttachment "C:\Users\Desktop\Email\Storage\example.jpg"
.Send

End If并确保文件email.jpg存在且路径正确

相关问题