Send HTML formatted email using PowerShell

Did you ever tried to send HTML formatted colour coded email using PowerShell ? I was trying to do it but didn’t get any good and useful information on it, but i finally manage to get it done.
So lets start:
For example i am sending a test email from my official account to my GMAIL account.
 the script will look like  this:

##############  Script start Here ##########
# $smtp variable contain the name/ip of your email server ##
# $to contain the email id whom you want to send email ###
# $from contain email of sender ###
# $Subject contain subject of the email.
# In Body we are defining some HTML coding in to our email message body
# <b> means BOLD
#<br> means Break go to next Line
#<a href> provide a link to the text
# <font color=red> , give the color to the font
$smtp = “Exchange-Server”
$to = “Aman Dhally <amandhally@gmail.com>”
$from = “Aman Singh <aman.dhally@analysysmason.com>”
$subject = “This is a Test of HTML Email”

$body = “Dear <b><font color=red>$to</b></font> <br>”
$body += “We are testing <b>HTML</b> email <br>”
$body += “Click <a href=
http://www.google.com>here</a> to open google <br>”
#### Now send the email using \> Send-MailMessage
send-MailMessage -SmtpServer $smtp -To $to -From $from -Subject $subject -Body $body -BodyAsHtml -Priority high
########### End of Script################

Note: Make sure you use –BodyasHtml parameter in Send-MailMessage otherwise it send as plain text format.
Now lets see how this email will look like 🙂

Send-MailMessage

Cool!!! it look exactly how we have define it in our Script 🙂
you can find more HTML coded which you can use in script from here

Leave a Reply

Your email address will not be published. Required fields are marked *

RELATED POST

HƯỚNG DẪN CÀI ĐẶT GMAIL SMTP CHO PRESTASHOP NĂM 2024

Gmail SMTP: Tăng cường Hệ thống Email Của Bạn Gmail SMTP hoạt động như thế nào? Gmail SMTP hoạt động…

MX vs SPF vs DMARC vs DKIM vs BIMI – Record Need for Mail Server

The domain name system (DNS) plays an important role in delivering email. The owner of a domain name (for example: @gmail.com)…

What Is a DMARC Record + How to Add One to Your DNS [Easy]

Do you want to create a DMARC record? A DMARC record provides important instructions for how messages failing email authentication…

Hướng dẫn triển khai SSL cho MDaemon Mail server

Quy trình triển khai SSL cho MDaemon mail server như sau: Bước 1: Khởi tạo CSR trên server 1. Đăng…