gpt4 book ai didi

excel - 将消息发送到非 Outlook 客户端时,VBA HTML 格式丢失

转载 作者:行者123 更新时间:2023-12-04 21:05:55 29 4
gpt4 key购买 nike

我有一个宏,可以解析电子表格并根据解析的数据编译电子邮件。我面临的问题是视觉格式。
当我使用宏将电子邮件发送到 Outlook 电子邮件地址时,一切正常(html 代码有效),但是当我将相同的电子邮件发送到 gmail Web 客户端时,我丢失了 html 并且我的电子邮件已发送纯文本。
这是我的电子邮件功能的样子:

Function OutlookEmail(SendTo As String, subject As String, Message As String, send As Boolean)
Dim Outlook As Object, NewMail As Object, SafeItem As Object, Attach As Object

Set Outlook = CreateObject("Outlook.Application")
Set SafeItem = CreateObject("Redemption.SafeMailItem")
Set NewMail = Outlook.CreateItem(0)
SafeItem.Item = NewMail

With SafeItem
.Recipients.Add SendTo
.Recipients.ResolveAll
.subject = subject
.HTMLBody = Message
End With

If send = True Then SafeItem.send
If send = False Then SafeItem.display

Set Outlook = Nothing
Set NewMail = Nothing
Set SafeItem = Nothing
Set Attach = Nothing
End Function


Redemption 是一个电子邮件插件,可帮助自动发送所有内容,Message 包含 HTML 和内联 css 格式的文本。

这是发送到 Outlook 客户端时的样子:
http://snag.gy/bSLTp.jpg

除了下面,这是一个带有一些格式的简单循环。
CSS变量:
Dim CSS_p As String, CSS_phone As String, CSS_table As String, CSS_th As String, CSS_td As String
Dim CSS_first As String, CSS_last As String, CSS_jlist As String, CSS_warning As String, CSS_accent As String

CSS_p = " style='line-height: 16px;color: #666;margin-top: 10px; margin-bottom: 15px; margin-left: 20px; margin-right: 10px;'"
CSS_phone = " style='font-weight: bold;'"
CSS_table = " style='font-size: 14px; text-align: center;'"
CSS_th = " style='padding: 0 0.5em; text-align:center; " & _
"border-top: 1px solid #FB7A31; border-bottom: 1px solid #FB7A31; background-color: #FFC;'"
CSS_td = " style='border: 1px solid #CCC;padding: 0 0.5em; text-align:center;'"
CSS_first = " style='border-top: 1px solid #CCC; border-bottom: 1px solid #CCC; border-left: none; border-right: 1px solid #CCC'"
CSS_last = " style='border-top: 1px solid #CCC; border-bottom: 1px solid #CCC; border-left: 1px solid #CCC; border-right: none;'"
CSS_jlist = " style='border-collapse:collapse;line-width:1px;'"
CSS_warning = " style='line-height: 16px;color: red;margin-top: 10px; margin-bottom: 15px; margin-left: 20px; margin-right: 10px;'"
CSS_accent = " style='text-decoration:underline; font-weight:bold;'"

表格内容:
job_list = job_list & "<tr><td" & CSS_td & ">" & account & "</td>" & _
"<td" & CSS_td & ">" & location & "</td>" & _
"<td" & CSS_td & ">" & address & "</td>" & _
"<td" & CSS_td & ">" & work_order & "</td>" & _
"<td" & CSS_td & ">" & description & "</td>" & _
"<td" & CSS_td & ">" & service_date & "</td></tr>"

信息:
           email_body = "<html><head></head>" & _
"<body><p" & CSS_p & ">" & Greeting() & _
"</p>" & _
"<p" & CSS_p & "> Our records indicate that we have not received signed paperwork for the " & _
"following jobs as of yet:</p>" & _
"<table" & CSS_table & ">" & _
"<th" & CSS_th & ">Account</th>" & _
"<th" & CSS_th & ">Store Number</th>" & _
"<th" & CSS_th & ">Address</th>" & _
"<th" & CSS_th & ">Work Order#</th>" & _
"<th" & CSS_th & ">Description</th>" & _
"<th" & CSS_th & ">Service Date</th>" & _
job_list & "</table>" & _
"<p" & CSS_p & ">Please remember to submit the work orders, your invoices and checklists (if applicable) for the jobs " & _
"referenced above." & _
"<p" & CSS_p & ">You may send the paperwork via:</p>" & _
"<ul><li>Fax to (000) 000 0000 or,</li>" & _
"<li>Email to: xx@xxxxxxxxx.com (please indicate your crew code in the email subject)</li></ul>" & _
"<p" & CSS_p & ">All work orders must be signed and stamped by the store manager on duty at the time of service. If the " & _
"stamp is not available, please ask the manager to write that on the work order (and checklists if applicable), as well as " & _
"initial the note. Submitting un-signed and un-stamped paperwork, that is not properly filled out, may result in your " & _
"invoices being rejected.</p>" & _
"<p" & CSS_p & ">Thank you for your cooperation.</p>" & _
HTMLSignature & "</body></html>"
OutlookEmail SendTo:=email, subject:=email_subject, Message:=email_body, send:=True

最佳答案

您忘记将电子邮件消息的正文格式设置为 HTML,Outlook 非常擅长自动检测这些内容。

将 BodyFormat 设置为 olFormatHTML 女巫我认为是值 2

我在这台机器上没有兑换,所以我可以检查,但它应该类似于

With SafeItem
.Recipients.Add SendTo
.Recipients.ResolveAll
.subject = subject
.HTMLBody = Message
.BodyFormat = olFormatHTML ' or the value 2
End With

关于excel - 将消息发送到非 Outlook 客户端时,VBA HTML 格式丢失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19256711/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com