我目前正在尝试编写一个自动化 VBA 脚本,该脚本将使用 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
尝试改变这些线条
"<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
.AddAttachment "C:\Users\foodpanda\Desktop\Email\Storage\email.jpg"
.AddAttachment "C:\Users\Desktop\Email\Storage\example.jpg"
.Send
End If
并确保文件email.jpg存在且路径正确