vba - 如何从 MS Access 使用 VBA 发送 HTML 电子邮件
问题描述
我自己找到了解决方案。我没有将 HTML 存储在变量 Text 中,而是直接使用数据库中的 html 字段。所以我现在使用 .htmlbody = rs.fields("tekst") 这很好用!
发送纯文本邮件没有问题。如果我尝试发送 HTML,它总是以纯文本形式发送。
我尝试使用.HTMLbody
而不是,.Body
但仍然是同样的问题。
HTML 文本保存在 MS Access 表的字段tekst
中,格式为备忘录 - 富文本。我正在使用 Gmail 帐户。
Sub SendGmail()
'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") = 25
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") = _
"myaddress@gmail.com"
Mail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendpassword") = _
"*********"
'Update the configuration fields
Mail.Configuration.Fields.Update
'get text
Set rs = CurrentDb.OpenRecordset("select tekst from tekst")
rs.MoveFirst
txt = "<html><body>" & rs.Fields("tekst") & "</body></html>"
'Set All Email Properties
With Mail
.AutoGenerateTextBody = False
.Subject = "test123"
.From = "myaddress@gmail.com"
.To = "toaddress"
.CC = ""
.HTMLBody = txt
'.AddAttachment ("Folder Address") 'To attach Documents in mail
End With
End Sub
解决方案
尝试将ContentMediaType属性设置为"text/html"
.
推荐阅读
- swift - Swift,带有完成处理程序的网络调用不起作用
- c++ - 错误:无法将“float*”转换为“float”作为回报
- oracle - 当视图用于显示 Oracle Apex 中的现有记录时,如何在表中更新或创建新记录?
- python - 如何从嵌套列表中按 IP 地址提取端口
- mysql - sql 对 USERS 销售额求和
- django - Django elasticsearch DSL DRF 建议问题
- reactjs - Algolia instasearch 设计,如 reactjs.org 上的点击量 - reactjs
- yocto - Yocto 在 64 位系统上为 32 位构建了一些食谱
- rust - 货物功能是否可以删除依赖项?
- firebase - 我们可以在 Firebase 测试实验室中使用 flutter_driver 运行自动化测试吗?