I am trying to make my body of text convert to HTML so it does not show as plain text in my email.
Here is the code
$From = ""
$To = ""
$SMTPServer = ""
$SMTPPort = "587"
$Username = ""
$Password = ""
$subject = "Test Powershell"
$body = $htmlreport
$bodyAsHtml = $true
$smtp = New-Object System.Net.Mail.SmtpClient($SMTPServer, $SMTPPort);
$smtp.EnableSSL = $true
$smtp.Credentials = New-Object System.Net.NetworkCredential($Username, $Password);
$smtp.Send($From, $To, $subject, $body);
I cant see to get the report to send as HTML.
Instead of passing the individual strings to
$smtp.Send()
, you should create aMailMessage
object and send that instead: