Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save constructor-igor/7837e1bd9efa1a7b159d to your computer and use it in GitHub Desktop.
Save constructor-igor/7837e1bd9efa1a7b159d to your computer and use it in GitHub Desktop.
Powershell: embed 2 images to Outlook emails body
function SendEmailWithEmbeddedImages([String] $to, [String] $subject, [String] $body, [String] $attachment, [array] $imageFiles)
{
$htmlText = "<HTML>{0}</HTML>"
foreach ($imageFile in $imageFiles) {
$fileName = ExtractFileName $imageFile
$imageTag = [string]::Format("<img src='cid:{0}'>", $fileName)
$htmlText = $htmlText + $imageTag
}
$Outlook = New-Object -ComObject Outlook.Application
$Mail = $Outlook.CreateItem(0)
$Mail.To = $to
$Mail.Subject = $subject
$Mail.HTMLBody = [string]::Format($htmlText, $body)
#$Mail.Body = $body
$Mail.Attachments.Add($attachment)
foreach ($imageFile in $imageFiles) {
$Mail.Attachments.Add($imageFile)
}
$Mail.Send()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment