This topic contains 3 replies, has 2 voices, and was last updated by Jeff Scharfenberg 1 year, 2 months ago.
-
AuthorPosts
-
February 4, 2017 at 7:38 pm #63582
I recently have setup a script for veeam backup and it works really well, minus the email it sends to me. It's supposed to send a clean looking HTML but instead i get this....
BODY{font-family: Arial; font-size: 10pt;}TABLE{border: 1px solid black; border-collapse: collapse;}TH{border: 1px solid black; background: #dddddd; padding: 5px; }TD{border: 1px solid black; padding: 5px; } NameStart TimeEnd TimeResultDetails server_2017-02-04T132822 2/4/2017 1:28:22 PM2/4/2017 1:31:16 PMSuccessUsing source proxy hypervhost (onhost)
What commands do I need to use to have this translate into an actual HTML and send so it looks as it should?
-
February 5, 2017 at 5:50 pm #63603
If you're using Send-MailMessage, you need to specify -BodyAsHTML.
-
February 6, 2017 at 5:24 pm #63639
Here is the major parts of the email part. It's not using Send-MailMessage, but beneath it maybe?
$message = New-Object System.Net.Mail.MailMessage $message.subject = $subject $message.body = $MesssagyBody | ConvertTo-Html -head $style | Out-String $message.to.add($to) $message.cc.add($cc) $message.from = $username #$message.attachments.add($attachment) $smtp = New-Object System.Net.Mail.SmtpClient($SMTPServer, $SMTPPort); $smtp.EnableSSL = $true $smtp.Credentials = New-Object System.Net.NetworkCredential($Username, $Password); $smtp.send($message) write-host "Mail Sent"
-
February 7, 2017 at 1:31 pm #63667
I was very surprised to get the email in an HTML format last night. It is a tad off to the right when holding the phone in normal mode, and it's perfect when horizontal. This is something I can work with for now.
I think what did it for my code was to add...
$message.IsBodyHtml = $True and I commented out the Out-String in the $message.body line.
$message = New-Object System.Net.Mail.MailMessage $message.subject = $subject $message.IsBodyHTML = $True $message.body = $MesssagyBody | ConvertTo-Html -head $style #| Out-String $message.to.add($to) $message.cc.add($cc) $message.from = $username $smtp = New-Object System.Net.Mail.SmtpClient($SMTPServer, $SMTPPort); $smtp.EnableSSL = $true $smtp.Credentials = New-Object System.Net.NetworkCredential($Username, $Password); $smtp.send($message) write-host "Mail Sent"
Thanks for all your help!
-
AuthorPosts
You must be logged in to reply to this topic.