bcapello
asked on
How can I embed images in an HTML email message sent via Exchange Powershell?
I have a working Powershell script that looks at an input file for two variables (recipients and language code). each email that is sent contains a header and footer image. But, the email that Outlook receives doesn't automatically display the images. the user has to allow Outlook to download the images. Is there a way around this? Is it possible to embed the images in the HTML formatted email that is sent via Powershell?
Here is my script below:
Start-Transcript -PATH UserImportLog.txt -append
# Language specific text
$Subject = @{
en = @"
Service Request Approval
"@
fr = @"
Approbation d’une demande de service
"@
}
$msg = @{
en = @"
<img src="\\sharename\Images\he ader_en.pn g" /><br>
<p><b><font color="#FF9900">Service Request Approval:</font></b></p>
<p>You have been identified as the approver of one or several Service Requests.</p>
<p><b>Your action (approval / rejection / reassignment) is important because the requests cannot be fulfilled without your approval.</b></p>
<p>Therefore, please go to the portal to validate these requests by clicking on the following link: http://test.domain.com/pages/approval-
dashboard.aspx</p>
<p></p>
<p>For further information or assistance, please contact your local Service Desk.</p>
<p>Best regards,</p>
<p>The IS Team</p>
<p>PS: This e-mail was generated automatically. Please do not reply directly to this e-mail.</p>
<img src="\\sharename\Images\fo oter.png"> <br>
"@
fr = @"
<img src="\\sharename\Images\he ader_fr.pn g" /><br>
<p><b><font color="#FF9900">Approbatio n d’une demande de service:</font></b></p>
<p>Vous avez été identifié comme étant l’approbateur d’une ou plusieurs demandes de services INIT.</p>
<p><b>Votre action (validation / refus / réassignation) est importante car aucun traitement ne pourra être effectué par les
équipes IS tant que ces demandes ne seront pas approuvées.</b></p>
<p>Nous vous invitons donc à vous connecter à votre portail pour valider ces demandes en cliquant sur ce lien :
http://test.domain.com/pages/approval-dashboard.aspx</p>
<p></p>
<p>Pour tout complément d’information ou assistance, n’hésitez pas à contacter votre Service Desk.</p>
<p>Cordialement,</p>
<p>L’équipe IS</p>
<p>PS: Ce message a été envoyé automatiquement, merci de ne pas y répondre</p>
<img src="\\servername\Images\f ooter.png" ><br>
"@
}
#Importing the input file with two variables (emailaddress,languagecode )
Import-Csv -Path UserImport.csv | foreach-object {
Send-MailMessage -SmtpServer servername -From "smtpaddress" -To $_.emailaddress -BodyasHTML -subject $subject[$_.languagecode] -Body $msg
[$_.languagecode] -Encoding ([System.Text.Encoding]::U TF8)
}
Stop-Transcript
Here is my script below:
Start-Transcript -PATH UserImportLog.txt -append
# Language specific text
$Subject = @{
en = @"
Service Request Approval
"@
fr = @"
Approbation d’une demande de service
"@
}
$msg = @{
en = @"
<img src="\\sharename\Images\he
<p><b><font color="#FF9900">Service Request Approval:</font></b></p>
<p>You have been identified as the approver of one or several Service Requests.</p>
<p><b>Your action (approval / rejection / reassignment) is important because the requests cannot be fulfilled without your approval.</b></p>
<p>Therefore, please go to the portal to validate these requests by clicking on the following link: http://test.domain.com/pages/approval-
dashboard.aspx</p>
<p></p>
<p>For further information or assistance, please contact your local Service Desk.</p>
<p>Best regards,</p>
<p>The IS Team</p>
<p>PS: This e-mail was generated automatically. Please do not reply directly to this e-mail.</p>
<img src="\\sharename\Images\fo
"@
fr = @"
<img src="\\sharename\Images\he
<p><b><font color="#FF9900">Approbatio
<p>Vous avez été identifié comme étant l’approbateur d’une ou plusieurs demandes de services INIT.</p>
<p><b>Votre action (validation / refus / réassignation) est importante car aucun traitement ne pourra être effectué par les
équipes IS tant que ces demandes ne seront pas approuvées.</b></p>
<p>Nous vous invitons donc à vous connecter à votre portail pour valider ces demandes en cliquant sur ce lien :
http://test.domain.com/pages/approval-dashboard.aspx</p>
<p></p>
<p>Pour tout complément d’information ou assistance, n’hésitez pas à contacter votre Service Desk.</p>
<p>Cordialement,</p>
<p>L’équipe IS</p>
<p>PS: Ce message a été envoyé automatiquement, merci de ne pas y répondre</p>
<img src="\\servername\Images\f
"@
}
#Importing the input file with two variables (emailaddress,languagecode
Import-Csv -Path UserImport.csv | foreach-object {
Send-MailMessage -SmtpServer servername -From "smtpaddress" -To $_.emailaddress -BodyasHTML -subject $subject[$_.languagecode] -Body $msg
[$_.languagecode] -Encoding ([System.Text.Encoding]::U
}
Stop-Transcript
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I am using Powershell v2. -inlineattachments parameter only works with v3.
Note: The script shown modifies the standard Send-MailMessage cmdlet by adding -InlineAttachments. It works with PS2.
ASKER