Script repository
The script sends an email notification containing an inline image. To execute the script, create a business rule, custom command or scheduled task configured for the required object type.
Parameters
$to- the email address of the notification recipient.$subject- the email notification subject.$imagePath- the path to the image that will be embedded into the email notification.$messageTemplate- Specifies the email notification template. The template must be in the HTML format. In the template, the{0}placeholder will be replaced with the image specified by$imagePath.
Adaxes 2023.2 and older
$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)Adaxes 2025.1 and newer
$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([System.IO.File]::ReadAllBytes($imagePath))
# Build mail message.
$html = [System.String]::Format($messageTemplate, $imageBase64String)
# Send mail
$Context.SendMail($to, $subject, $NULL, $html)
Comments 2
You must be signed in to comment.
Shawn
I was receiving the following error.
So I updated this.
$imageBase64String = [Convert]::ToBase64String((Get-Content $imagePath -Encoding Byte))With this.
$imageBase64String = [Convert]::ToBase64String([System.IO.File]::ReadAllBytes($imagePath))I was then able to send the email. It may be because we're on Adaxes 2026.1, which uses PowerShell 7. I believe version 2023.2 and earlier use PowerShell 5, so perhaps that script will work with those versions.
Support
Hello Shawn,
Thank you for pointing out the behavior. We updated the article accordingly.