在Outlook电子邮件中显示表

时间:2015-09-04 19:16:23

标签: html email outlook autoit

我写了一个AutoIT程序,通过SMTP服务器为我公司的IT部门自动发送电子邮件警报。此警报包含使用HTML()生成的表。发送警报后,使用Outlook 2007-2010的收件人将看到纯文本HTML标记而不是漂亮的表。我已经搜索了我能想到的每个可能的解决方案,但是我仍然无法获得HTML渲染。

Html存储在$ as_Body变量中。我目前正在发送电子邮件: $ Response = _INetSmtpMail($ s_SmtpServer,$ s_FromName,$ s_FromAddress,$ s_ToAddress,$ s_Subject,$ as_Body,@ ComputerName,-1,0)

编辑:有趣的是,StackOverflow的电子邮件注册使用html表在注册此站点时显示格式正确的消息。消息(html)显示正常/正确没有问题。但是,如果我从我的收件箱邮件中复制html代码并通过我的程序提供它并将其发送到我的收件箱,则HTML将显示为纯文本。

3 个答案:

答案 0 :(得分:0)

在Outlook中,转到文件>选项>信任中心。

在电子邮件安全选项中,检查您是否未选中

的复选框
  
    

以纯文本格式阅读所有标准邮件。

  

如果启用了复选框,则可能会导致问题。

答案 1 :(得分:0)

我改变了方法并提出了以下工作解决方案。它是一个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")

答案 2 :(得分:-1)

Outlook使用Word呈现邮件正文的HTML标记。我建议将HTML标记保存在文件中并在Word中打开它。你还看到HTML标签而不是内容吗?

您可以在MSDN的以下文章中阅读有关受支持和不受支持的HTML元素,属性和级联样式表属性的更多信息: