Elad-a
asked on
Use a .HTM file as a body of an email sent via PowerShell
Hi,
I use powershell to generate an HTM report that i want to send over to my users via Powershell.
Thing is that I dont want to send it as an attachment but as the body of the mail I'm sending to my users.
There are lots of PS1 scripts out there to send mail via powershell but I cant get any of them to send an HTM formatted mail with the HTM file as the body.
Instead i just get an email with the below content:
Can you help?
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <style>BODY{background-col or:peachpu ff;}TABLE{ border-wid th: 1px;border-style: solid;border-color: black;border-collapse: collapse;}TH{border-width: 1px;padding: 0px;border-style: solid;border-color: black;background-color:pal egoldenrod }TH{border -width: 1px;padding: 0px;border-style: solid;border-color: black;background-color:pal egoldenrod }</style> </head><body> <H2>Mail ITem Count Harts</H2> <table> <colgroup> <col> <col> <col> <col> <col> <col> </colgroup> <tr><th>From: 04/24/2009 10:09:17</th><th>To:04/25/ 2009 10:09:17 </th><th>there were</th><th>4</th><th>E-M ail's To</th><th>mail accountname </th></tr> </table></body></html>
I use powershell to generate an HTM report that i want to send over to my users via Powershell.
Thing is that I dont want to send it as an attachment but as the body of the mail I'm sending to my users.
There are lots of PS1 scripts out there to send mail via powershell but I cant get any of them to send an HTM formatted mail with the HTM file as the body.
Instead i just get an email with the below content:
Can you help?
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <style>BODY{background-col
There's flag for this in the MailMessage Class (IsBodyHTML property), going to see if it works and I'll pop in a sample.
Chris
ASKER
Wow chris your the best!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks Chris, ill try it out and let you know..
Thanks,
Jason.
Thanks,
Jason.
ASKER
chris,
To add a subject line i'd just modify :
$MailMessage = New-Object System.Net.Mail.MailMessag e($From, $To)
to be
$MailMessage = New-Object System.Net.Mail.MailMessag e($From, $To,$subject)
correct?
Thanks
Jason.
To add a subject line i'd just modify :
$MailMessage = New-Object System.Net.Mail.MailMessag
to be
$MailMessage = New-Object System.Net.Mail.MailMessag
correct?
Thanks
Jason.
Not according to the documentation :) The constructor for MailMessage is limited to To / From details.
Instead try:
$MailMessage = New-Object System.Net.Mail.MailMessag
$MailMessage.Subject = "Your Subject"
$MailMessage.IsBodyHtml = $True
$MailMessage.Body = $HTMLBody
Chris
Oops I take it back, and you're right. I missed the last constructor and it should work with your version as well.
In fact it should work with:
$MailMessage = New-Object System.Net.Mail.MailMessag
So we only have to set IsBodyHtml outside of the constructor.
Chris
ASKER
Chris Dent is the Man!
both use plain text