We use cookies to improve your experience.
By your continued use of this site you accept such use.
For more details please see our privacy policy and cookies policy.

Script Repository

Send email notification with inline image

February 24, 2021 Views: 3296

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
Leave a comment
Loading...

Got questions?

Support Questions & Answers