【发布时间】:2020-05-20 10:42:52
【问题描述】:
我自己找到了解决方案。我没有将 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
【问题讨论】:
标签: vba ms-access gmail ms-access-2010 cdo.message