-3

I have wrote an AutoIT program to automate sending out email alerts via a SMTP server for my company's IT department. This alert contains a table that is made using HTML(). Once the Alert is sent out the recipients, who use Outlook 2007-2010, are seeing the plain text HTML tags instead of the nice tables. I have searched for every possible solution I could think of however I still can not get the HTML to render at all.

The Html is stored in the $as_Body variable. I am currently sending the email like so: $Response = _INetSmtpMail ($s_SmtpServer, $s_FromName, $s_FromAddress, $s_ToAddress, $s_Subject, $as_Body, @ComputerName, -1, 0)

Edit: Funny thing is the email registration for StackOverflow uses html tables to display a nicely formatted message when registering for this site. The message (html) displays fine/properly without issue. However if I copy the html code, as is, from my inbox message and feed it though my program and send it to my inbox the HTML will show up as plain text.

Duck
  • 11
  • 1
  • 5
  • while sending MAiL using SMTP you will have an option is `IsHTML`. find it. in .Net it is `IsBodyHtml` boolean. [This](http://stackoverflow.com/questions/3918747/send-an-email-with-autoit) may help you – J Santosh Sep 04 '15 at 19:19
  • https://www.autoitscript.com/wiki/OutlookEX_UDF_-_Mail_Item – J Santosh Sep 04 '15 at 19:25

3 Answers3

0

In Outlook go to File>Options>Trust Center.

In Email security option check that you have not checked the check-box for

Read all standards mail in plain text.

If check-box is enabled, that may cause the issue.

vish
  • 901
  • 1
  • 7
  • 20
0

I changed my approach and came up with the following working solution. Its a Auto IT script that accepts the appropriate variable to send an email then inputs the variable into a VBS script, writes it to a file, executes it, then deletes the VBS script. It does require Outlook to be installed on the machine running the script.

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")
Duck
  • 11
  • 1
  • 5
-1

Outlook uses Word for rendering HTML markup of message bodies. I'd suggest saving the HTML markup in a file and opening it in Word. Do you still see the HTML tags instead of the content?

You can read more about supported and unsupported HTML elements, attributes, and cascading style sheets properties in the following articles in MSDN:

Eugene Astafiev
  • 47,483
  • 3
  • 24
  • 45