Script Repository


Send email notification with inline image

October 26, 2017
1417

The script sends an email notification containing an inline image.

Parameters:

  • $to - specifies the recipient of the notification;
  • $subject - specifies the email message subject;
  • $imagePath - specifies a path to the file with the image that will be embedded in the notification;
  • $messageTemplate - specifies the email notification template. The template must be in the HTML format. The {0} placeholder in the template will be replaced with the image specified by $imagePath.
    You can use value references in the parameters (e.g. %mail%, %username%). They will be replaced with property values of the AD object for which the script is executed.
Edit Remove
PowerShell
$to = "%mail%" # TODO: modify me
$subject = "Your Account Information" # TODO: modify me
$imagePath = "\\Server\Share\Resources\%company%Logo.png" # TODO: modify me
$messageTemplate = @"
<html><body style='font-family:Calibri, sans-serif; font-size: 14px'>
<p>Hello %name%,</p>
<p>Your username is %sAMAccountName%, your initial password is %unicodePwd%.</p>
<p>Best regards,</p>
<hr />
<p>Acme Support Team</p>
<p><img src='data:image/png;base64,{0}'></p>
</body></html>
"@ # TODO: modify me

# Convert image to Base64 string
$imageBase64String = [Convert]::ToBase64String((Get-Content $imagePath -Encoding Byte))

# Build mail message
$html = [System.String]::Format($messageTemplate, $imageBase64String)

# Send mail
$Context.SendMail($to, $subject, $NULL, $html)


Comments ( 0 )
No results found.
Leave a comment