excel - 使用 Excel VBA 在 CDO 邮件中发送电子邮件签名中的图像时出错
问题描述
我需要发送带有我公司标志的自动电子邮件签名。
我正在使用邮件对象的 HTMLBody 属性,但它不显示图像。相反,它显示了一个符号和 img HTML 标记的 alt 属性。
是否有一个特殊的目录,我必须在其中放置图像文件才能在邮件正文中使用它们?
Sub AutoMail()
'creating a CDO object
Dim Mail As CDO.Message
Set Mail = New CDO.Message
'Enable SSL Authentication
Mail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True
'Make SMTP authentication Enabled=true (1)
Mail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
'Set the SMTP server and port Details
'Get these details from the Settings Page of your Gmail Account
Mail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver") = _
"smtp.gmail.com"
Mail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 465
Mail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
'Set your credentials of your Gmail Account
Mail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusername") = _
"****@****.com"
Mail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendpassword") = _
"*****"
'Update the configuration fields
Mail.Configuration.Fields.Update
'Set All Email Properties
With Mail
.Subject = "Test"
.From = "***@****.com"
.TextBody = "Hi"
.HTMLBody = "(message) <br> <br> <img alt='hi' src='C:\logo.png'>"
End With
'To send the mail
Mail.Send
Set Mail = Nothing
End Sub
解决方案
您可以将图像上传到任何 Web 服务器,并为上传的图像添加 URL。但这种方式并不能保证图像将显示在收件人一侧的 Outlook 中,因为 Outlook 默认阻止加载此类图像。
最可靠的方法是将图像附加到邮件项,然后将 CID 属性添加到它们。在邮件正文中,您可以使用附件上设置的 CID 属性来引用此类图像。在使用宏文章在新消息中嵌入图像中阅读更多相关信息。
推荐阅读
- python - 由 gunicorn 运行的 Flask 应用程序在一段时间后被挂起
- asp.net-core - ASP .NET Core webapi 在中间件中设置 cookie
- javascript - if条件的奇怪执行
- google-analytics - 即使该维度的数据不可用,也可以从 Google Analytics 获取维度数据
- gzip - Flink如何容错将数据下沉到hdfs作为gzip压缩?
- openjfx - 当“库”节点丢失时,Netbeans 11 如何将库添加到项目中?
- variables - 如何将 Terraform 配置器“local-exec”输出存储在局部变量中并在“remote-exec”中使用变量值
- azure-logic-apps - LogicApps 场景登录、下载、压缩
- java - 使用资源锁进行并行测试?
- python - 在 arcsin [RuntimeWarning] 中遇到无效值