Link to home
Start Free TrialLog in
Avatar of carbonbase
carbonbaseFlag for United Kingdom of Great Britain and Northern Ireland

asked on

sending email as html - PowerShell function

Hello, I have the following PowerShell function which sends an email, it sends email as plain text, I would like to update the function so that it sends email as html:

function SendMail ($SMTPserver,$sendermailaddress,$usermailaddress,$mailBody)            
    $smtpServer = $SMTPserver            
    $msg = new-object Net.Mail.MailMessage            
    $smtp = new-object Net.Mail.SmtpClient($smtpServer)            
    $msg.From = $sendermailaddress            
    $msg.Subject = $mailSubject           
    $msg.Body = $mailBody     

# call SendMail 

 SendMail $SMTPserver $sendermailaddress $usermailaddress $mailBody          

Open in new window

Thanks in advance.
Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

try set the IsBodyHtml property

MailMessage.IsBodyHtml Property

$msg.IsBodyHTML = $true

Open in new window

Avatar of oBdA

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Yeah 1st thought on this is , why are you using .NET when there's a built-in PS command that does that.

Use the Send-MailMessage as oBdA suggested.

Avatar of carbonbase


Thanks to everyone for your comments!