Create professional looking email notifications and newsletters with PowerShell.

Sending rich content emails in the HTML format, including their attachments and CID embedded images. The approach uses the .Net MailMessage class and conversion to a byte array for raw data submission to an email service like AWS SES or SendGrid.

PowerShell Code

Example Use

$logo = '<imageFile.png>'
$att1 = New-Object System.Net.Mail.Attachment($logo) 
$att1.ContentDisposition.Inline = $True 
$att1.ContentDisposition.DispositionType = "Inline" 
$att1.ContentType.MediaType = "image/png" 
$att1.ContentID = "att1"

$mailMessage = New-Object Net.Mail.MailMessage
$mailMessage.From = 'Someone<>'
$mailMessage.IsBodyHtml = $true

$mailMessage.Body = '<Your HTML Body>'
# href links in your body should reference your
# content ids ie. 'cid:att1' for the image attached.
$mailMessage.Subject = 'Your subject'
$raw_data = ConvertTo-RawDataMailMessage($mailMessage)

# For Amazon SES
Send-SES2Email -Raw_Data $raw_data