Reputation: 11
Hi I am trying to edit the HTML email template using powershell which has some pictures and colours. I need to edit and replace some content in email and retain the html body. When i try the below script it's converting to text format
$file= 'FILE PATH '
$outlook= New-Object -ComObject outlook.application
$msg= $outlook.createitemfromtemplate($file)
$msg.body= $msg.body -replace "December\d*", "TEST$a"
$msg.saveas($file)
Upvotes: 0
Views: 2155
Reputation: 1
I was having the same issue than I used $mail.Save() after replacing de part I want on html body than everything worked. Without saving before sending I got an text message rather than html.
Upvotes: 0
Reputation: 229
You need to use HTMLBody and not body. Because you are telling it to use plane text in the email rather than HTML. Hope this helps.
$file= 'C:\Temp\template.msg'
$outlook= New-Object -ComObject outlook.application
$msg= $outlook.createitemfromtemplate($file)
$msg.HTMLbody = $msg.HTMLbody.Replace("color2", "color")
$msg.saveas($file)
#$file | ConvertTo-Html #if needed
Test scenario:
Code was ran:
After:
Upvotes: 1