在 Outlook 电子邮件中显示 Table
Displaying a Table in Outlook emails
我编写了一个 AutoIT 程序,通过 SMTP 服务器为我公司的 IT 部门自动发送电子邮件警报。此警报包含使用 HTML() 生成的 table。发出警报后,使用 Outlook 2007-2010 的收件人将看到纯文本 HTML 标签,而不是漂亮的 table 标签。我已经搜索了所有我能想到的可能的解决方案,但是我仍然无法让 HTML 呈现。
Html 存储在 $as_Body 变量中。我目前正在发送这样的电子邮件:
$Response = _INetSmtpMail ($s_SmtpServer, $s_FromName, $s_FromAddress, $s_ToAddress, $s_Subject, $as_Body, @ComputerName, -1, 0)
编辑:有趣的是 Whosebug 的电子邮件注册使用 html tables 在注册此站点时显示格式良好的消息。消息 (html) 显示 fine/properly 没有问题。但是,如果我按原样从我的收件箱消息中复制 html 代码,并通过我的程序将其提供并发送到我的收件箱,则 HTML 将显示为纯文本。
Outlook 使用 Word 呈现 HTML 邮件正文标记。我建议将 HTML 标记保存在文件中并在 Word 中打开它。您是否仍然看到 HTML 标签而不是内容?
您可以在 MSDN 中的以下文章中阅读有关受支持和不受支持的 HTML 元素、属性和级联样式表属性的更多信息:
在 Outlook 中转到文件>选项>信任中心。
在电子邮件安全选项中检查您是否没有选中
的复选框
Read all standards mail in plain text.
如果启用复选框,可能会导致问题。
我改变了方法并提出了以下可行的解决方案。它是一个 Auto IT 脚本,它接受适当的变量来发送电子邮件,然后将变量输入到 VBS 脚本中,将其写入文件,执行它,然后删除 VBS 脚本。它确实需要在机器上安装 Outlook 运行 脚本。
Global $recipient ;Who is the email going to
Global $recipientCC ;CC
Global $emailSubject ;Subject line of email - "$urgency & " Alert " & $emailSubject"
Global $urgency ;How urgent is the alert? High? Critical?
Global $issue ;Issue alert is being created for
Global $reportedTime ;Time issue was reported
Global $businessImpact ;the impact to the customer/store
Global $currentStatus ;the status to the customer/Store
Global $nextUpdate ;time of next update or explanation why issue is resolved
Global $alertType ;Type of Notice - Alert or Resolved
;Local $fromSD = 'Service Desk'
;Local $fromAddress = 'itservicedesk@IT.com'
$file = FileOpen(@scriptdir&"\email2.vbs", 1) ;open emial2.vbs and assign to $file
$ToAddress = $recipient
$CC = $recipientCC
$MessageSubject = $urgency & " Alert " & $emailSubject
$strHTML = "<HTML>"
$strHTML = $strHTML & "<HEAD>"
$strHTML = $strHTML & "<style>"
$strHTML = $strHTML & "h1 {background-color:#4F81BD; color:white; text-align: center;}"
$strHTML = $strHTML & "table, td {border-collapse: collapse; border: 1px solid #4F81BD;} "
$strHTML = $strHTML & "p {color:black}"
$strHTML = $strHTML & "</style>"
$strHTML = $strHTML & "</HEAD>"
$strHTML = $strHTML & "<BODY>"
$strHTML = $strHTML & "<p> </p>"
$strHTML = $strHTML & "<table width = 500>"
$strHTML = $strHTML & "<tr>"
$strHTML = $strHTML & "<td colspan = 2><h1> " & $alertType & " </h1></td>"
;$strHTML = $strHTML & "<td ></td>"
$strHTML = $strHTML & "</tr>"
$strHTML = $strHTML & "<tr>"
$strHTML = $strHTML & "<td><p>Issue: </p></td>"
$strHTML = $strHTML & "<td><p> " & $issue & " </p></td>"
$strHTML = $strHTML & "</tr>"
$strHTML = $strHTML & "<tr>"
$strHTML = $strHTML & "<td><p>Reported Time: </p></td>"
$strHTML = $strHTML & "<td><p> " & $reportedTime & " </p></td>"
$strHTML = $strHTML & "</tr>"
$strHTML = $strHTML & "<tr>"
$strHTML = $strHTML & "<td><p>Business Impact: </p></td>"
$strHTML = $strHTML & "<td><p> " & $businessImpact & " </p></td>"
$strHTML = $strHTML & "</tr>"
$strHTML = $strHTML & "<tr>"
$strHTML = $strHTML & "<td><p>Current Status: </p></td>"
$strHTML = $strHTML & "<td><p>" & $currentStatus & " </p></td>"
$strHTML = $strHTML & "</tr>"
$strHTML = $strHTML & "<tr>"
$strHTML = $strHTML & "<td><p>Next Update: </p></td>"
$strHTML = $strHTML & "<td><p>" & $nextUpdate & " </p></td>"
$strHTML = $strHTML & "</tr>"
$strHTML = $strHTML & "</table>"
$strHTML = $strHTML & "<p>- IT Service Desk</p><hr>"
$strHTML = $strHTML & "</BODY>"
$strHTML = $strHTML & "</HTML>"
$MessageBody = $strHTML ; assign HTML to messageBody
;$MessageAttachment = @scriptdir&"\"&"a.txt"
FileWriteLine($file, 'Dim ToAddress')
FileWriteLine($file, 'Dim FromAddress')
FileWriteLine($file, 'Dim MessageSubject')
FileWriteLine($file, 'Dim MessageBody')
;FileWriteLine($file, 'Dim MessageAttachment')
;FileWriteLine($file, 'Dim MessageAttachment2')
FileWriteLine($file, 'Dim CC')
FileWriteLine($file, 'Dim ol, ns, newMail')
FileWriteLine($file, 'ToAddress = "'& $ToAddress &'"')
FileWriteLine($file, 'MessageSubject = "'& $MessageSubject &'"' )
FileWriteLine($file, 'MessageBody = "'& $MessageBody&'"')
;FileWriteLine($file, 'MessageAttachment = "'& $MessageAttachment&'"' )
FileWriteLine($file, 'CC = "'&$CC&'"' )
FileWriteLine($file, 'Set ol = WScript.CreateObject("Outlook.Application")')
FileWriteLine($file, 'Set ns = ol.getNamespace("MAPI")')
FileWriteLine($file, 'ns.logon "","",true,false')
FileWriteLine($file, 'Set newMail = ol.CreateItem(olMailItem)')
FileWriteLine($file, 'newMail.SentOnBehalfOfName = "ITServicedesk@IT.com"') ; Send email from IT Service Desk
FileWriteLine($file, 'newMail.Subject = MessageSubject')
FileWriteLine($file, 'newMail.HtmlBody = MessageBody & vbCrLf')
FileWriteLine($file, 'newMail.CC = CC & vbCrLf')
FileWriteLine($file, "' validate the recipient, just in case...")
FileWriteLine($file, 'Set myRecipient = ns.CreateRecipient(ToAddress)')
FileWriteLine($file, 'Set myRecipient2 = ns.CreateRecipient(CC)')
FileWriteLine($file, 'myRecipient.Resolve')
FileWriteLine($file, 'If Not myRecipient.Resolved Then')
FileWriteLine($file, ' MsgBox "unknown recipient"')
FileWriteLine($file, 'Else')
FileWriteLine($file, ' newMail.Recipients.Add(myRecipient)')
;FileWriteLine($file, ' newMail.Attachments.Add(MessageAttachment)')
FileWriteLine($file, ' newMail.Send')
FileWriteLine($file, 'End If')
FileWriteLine($file, 'Set ol = Nothing')
FileClose($file)
Sleep(100)
Run('wscript.exe "'&@scriptdir&'\email2.vbs"',@scriptdir)
sleep(1000)
FileDelete(@scriptdir&"\email2.vbs")
我编写了一个 AutoIT 程序,通过 SMTP 服务器为我公司的 IT 部门自动发送电子邮件警报。此警报包含使用 HTML() 生成的 table。发出警报后,使用 Outlook 2007-2010 的收件人将看到纯文本 HTML 标签,而不是漂亮的 table 标签。我已经搜索了所有我能想到的可能的解决方案,但是我仍然无法让 HTML 呈现。
Html 存储在 $as_Body 变量中。我目前正在发送这样的电子邮件: $Response = _INetSmtpMail ($s_SmtpServer, $s_FromName, $s_FromAddress, $s_ToAddress, $s_Subject, $as_Body, @ComputerName, -1, 0)
编辑:有趣的是 Whosebug 的电子邮件注册使用 html tables 在注册此站点时显示格式良好的消息。消息 (html) 显示 fine/properly 没有问题。但是,如果我按原样从我的收件箱消息中复制 html 代码,并通过我的程序将其提供并发送到我的收件箱,则 HTML 将显示为纯文本。
Outlook 使用 Word 呈现 HTML 邮件正文标记。我建议将 HTML 标记保存在文件中并在 Word 中打开它。您是否仍然看到 HTML 标签而不是内容?
您可以在 MSDN 中的以下文章中阅读有关受支持和不受支持的 HTML 元素、属性和级联样式表属性的更多信息:
在 Outlook 中转到文件>选项>信任中心。
在电子邮件安全选项中检查您是否没有选中
的复选框Read all standards mail in plain text.
如果启用复选框,可能会导致问题。
我改变了方法并提出了以下可行的解决方案。它是一个 Auto IT 脚本,它接受适当的变量来发送电子邮件,然后将变量输入到 VBS 脚本中,将其写入文件,执行它,然后删除 VBS 脚本。它确实需要在机器上安装 Outlook 运行 脚本。
Global $recipient ;Who is the email going to
Global $recipientCC ;CC
Global $emailSubject ;Subject line of email - "$urgency & " Alert " & $emailSubject"
Global $urgency ;How urgent is the alert? High? Critical?
Global $issue ;Issue alert is being created for
Global $reportedTime ;Time issue was reported
Global $businessImpact ;the impact to the customer/store
Global $currentStatus ;the status to the customer/Store
Global $nextUpdate ;time of next update or explanation why issue is resolved
Global $alertType ;Type of Notice - Alert or Resolved
;Local $fromSD = 'Service Desk'
;Local $fromAddress = 'itservicedesk@IT.com'
$file = FileOpen(@scriptdir&"\email2.vbs", 1) ;open emial2.vbs and assign to $file
$ToAddress = $recipient
$CC = $recipientCC
$MessageSubject = $urgency & " Alert " & $emailSubject
$strHTML = "<HTML>"
$strHTML = $strHTML & "<HEAD>"
$strHTML = $strHTML & "<style>"
$strHTML = $strHTML & "h1 {background-color:#4F81BD; color:white; text-align: center;}"
$strHTML = $strHTML & "table, td {border-collapse: collapse; border: 1px solid #4F81BD;} "
$strHTML = $strHTML & "p {color:black}"
$strHTML = $strHTML & "</style>"
$strHTML = $strHTML & "</HEAD>"
$strHTML = $strHTML & "<BODY>"
$strHTML = $strHTML & "<p> </p>"
$strHTML = $strHTML & "<table width = 500>"
$strHTML = $strHTML & "<tr>"
$strHTML = $strHTML & "<td colspan = 2><h1> " & $alertType & " </h1></td>"
;$strHTML = $strHTML & "<td ></td>"
$strHTML = $strHTML & "</tr>"
$strHTML = $strHTML & "<tr>"
$strHTML = $strHTML & "<td><p>Issue: </p></td>"
$strHTML = $strHTML & "<td><p> " & $issue & " </p></td>"
$strHTML = $strHTML & "</tr>"
$strHTML = $strHTML & "<tr>"
$strHTML = $strHTML & "<td><p>Reported Time: </p></td>"
$strHTML = $strHTML & "<td><p> " & $reportedTime & " </p></td>"
$strHTML = $strHTML & "</tr>"
$strHTML = $strHTML & "<tr>"
$strHTML = $strHTML & "<td><p>Business Impact: </p></td>"
$strHTML = $strHTML & "<td><p> " & $businessImpact & " </p></td>"
$strHTML = $strHTML & "</tr>"
$strHTML = $strHTML & "<tr>"
$strHTML = $strHTML & "<td><p>Current Status: </p></td>"
$strHTML = $strHTML & "<td><p>" & $currentStatus & " </p></td>"
$strHTML = $strHTML & "</tr>"
$strHTML = $strHTML & "<tr>"
$strHTML = $strHTML & "<td><p>Next Update: </p></td>"
$strHTML = $strHTML & "<td><p>" & $nextUpdate & " </p></td>"
$strHTML = $strHTML & "</tr>"
$strHTML = $strHTML & "</table>"
$strHTML = $strHTML & "<p>- IT Service Desk</p><hr>"
$strHTML = $strHTML & "</BODY>"
$strHTML = $strHTML & "</HTML>"
$MessageBody = $strHTML ; assign HTML to messageBody
;$MessageAttachment = @scriptdir&"\"&"a.txt"
FileWriteLine($file, 'Dim ToAddress')
FileWriteLine($file, 'Dim FromAddress')
FileWriteLine($file, 'Dim MessageSubject')
FileWriteLine($file, 'Dim MessageBody')
;FileWriteLine($file, 'Dim MessageAttachment')
;FileWriteLine($file, 'Dim MessageAttachment2')
FileWriteLine($file, 'Dim CC')
FileWriteLine($file, 'Dim ol, ns, newMail')
FileWriteLine($file, 'ToAddress = "'& $ToAddress &'"')
FileWriteLine($file, 'MessageSubject = "'& $MessageSubject &'"' )
FileWriteLine($file, 'MessageBody = "'& $MessageBody&'"')
;FileWriteLine($file, 'MessageAttachment = "'& $MessageAttachment&'"' )
FileWriteLine($file, 'CC = "'&$CC&'"' )
FileWriteLine($file, 'Set ol = WScript.CreateObject("Outlook.Application")')
FileWriteLine($file, 'Set ns = ol.getNamespace("MAPI")')
FileWriteLine($file, 'ns.logon "","",true,false')
FileWriteLine($file, 'Set newMail = ol.CreateItem(olMailItem)')
FileWriteLine($file, 'newMail.SentOnBehalfOfName = "ITServicedesk@IT.com"') ; Send email from IT Service Desk
FileWriteLine($file, 'newMail.Subject = MessageSubject')
FileWriteLine($file, 'newMail.HtmlBody = MessageBody & vbCrLf')
FileWriteLine($file, 'newMail.CC = CC & vbCrLf')
FileWriteLine($file, "' validate the recipient, just in case...")
FileWriteLine($file, 'Set myRecipient = ns.CreateRecipient(ToAddress)')
FileWriteLine($file, 'Set myRecipient2 = ns.CreateRecipient(CC)')
FileWriteLine($file, 'myRecipient.Resolve')
FileWriteLine($file, 'If Not myRecipient.Resolved Then')
FileWriteLine($file, ' MsgBox "unknown recipient"')
FileWriteLine($file, 'Else')
FileWriteLine($file, ' newMail.Recipients.Add(myRecipient)')
;FileWriteLine($file, ' newMail.Attachments.Add(MessageAttachment)')
FileWriteLine($file, ' newMail.Send')
FileWriteLine($file, 'End If')
FileWriteLine($file, 'Set ol = Nothing')
FileClose($file)
Sleep(100)
Run('wscript.exe "'&@scriptdir&'\email2.vbs"',@scriptdir)
sleep(1000)
FileDelete(@scriptdir&"\email2.vbs")