如何在电子邮件末尾嵌入照片?



如何在电子邮件末尾嵌入照片?

Application.ScreenUpdating = False
Set OutApp = CreateObject("Outlook.Application")
On Error GoTo cleanup
For Each cell In Columns("B").Cells.SpecialCells(xlCellTypeConstants)
If cell.Value Like "?*@?*.?*" And _
LCase(Cells(cell.Row, "C").Value) = "yes" Then
Set OutMail = OutApp.CreateItem(0)
On Error Resume Next
With OutMail
.Display
End With
signature = OutMail.body
With OutMail
.To = cell.Value
.CC = "xxxxx@gmail.com; xxxxxx@hotmail.com"
.Subject = "Hello"
.body = "Dear " & Cells(cell.Row, "A").Value _
& vbNewLine & _
vbNewLine & _
vbNewLine & _
"Body" & _
signature
sourcefile = "XXXXXXX"
sourcefile1 = "XXXXXX"
.Attachments.Add sourcefile
.Attachments.Add sourcefile1
.Send
End With
Set OMail = Nothing
Set OApp = Nothing
On Error GoTo 0
Set OutMail = Nothing
End If
Next cell
cleanup:
Set OutApp = Nothing
Application.ScreenUpdating = True
End Sub

代码有效。

我想嵌入一个圣诞图像(JPEG(。我已经在互联网上进行了挖掘,但是无法弄清楚我可以使用什么命令功能来嵌入它。

您需要使用电子邮件的 HTMLBody 属性,因为纯文本不允许嵌入图像。

您还需要知道图像的文件名(不仅是路径(。可能有效的代码示例如下:

On Error GoTo cleanup
For Each cell In Columns("B").Cells.SpecialCells(xlCellTypeConstants)
If cell.Value Like "?*@?*.?*" And _
LCase(Cells(cell.Row, "C").Value) = "yes" Then
Set OutMail = OutApp.CreateItem(0)
On Error Resume Next
With OutMail
.Display
End With
signature = OutMail.body

With OutMail
.To = cell.Value
.CC = "xxxxx@gmail.com; xxxxxx@hotmail.com"
.Subject = "Hello"
imgpath = "c:XXXXXX"
sourcefile = "XXXXXXX"
sourcefile1 = "XXXXXX"
.Attachments.Add imgpath & sourcefile
.Attachments.Add imgpath & sourcefile1
.HTMLBody = "<body><p>Dear " & Cells(cell.Row, "A").Value _
& "<br/>& _
"Body" & _
signature & _
"<IMG src=""""cid:""" & sourcefile & """ width=200></body>"
.Send
End With
Set OMail = Nothing
Set OApp = Nothing

On Error GoTo 0
Set OutMail = Nothing
End If
Next cell
cleanup:
Set OutApp = Nothing
Application.ScreenUpdating = True
End Sub

相关内容

最新更新