I am using PS to import a csv, convert it to HTML, then send it in an email. It all works but Gmail ignores tags, so I cannot use CSS, and I cannot figure out how to do inline styling in PS.
All I want to do at this point is provide some padding to make the HTML more readable.
Here is my code...
$smtpServer = "x.x.x.x" $smtpFrom = "email@example.com" $smtpTo = "firstname.lastname@example.org" $messageSubject = "Blah Blah $((Get-Date).ToShortDateString())" $message = New-Object System.Net.Mail.MailMessage $smtpfrom, $smtpto $message.Subject = $messageSubject $message.IsBodyHTML = $true $summ = Import-Csv -Path 'C:\folder\file.csv' | ConvertTo-Html $message.Body = @" Hello, Blah Blah. $summ Thank you, Technology "@ $smtp = New-Object Net.Mail.SmtpClient($smtpServer) $smtp.Send($message)
It basically comes out in the email in table format but not very readable. I would like to add some padding to the text and maybe even BOLD the column names. Everything I try just makes the table disappear from the email, as it is not being rendered past Gmails preprocessor.
I tried something like this...
$pad = $summ -replace "\",'' $summ = Import-Csv -Path 'C:\folder\file.csv' | ConvertTo-Html -$pad
...but I am not sure if this is properly done.
Advice much appreciated. Bear in mind I cannot link to a css file or use a tag.
I am trying to do exactly this
But cannot get it to work.
Have you looked at our HTML Reporting free ebook (eBooks page)? It might not be exactly what you want, but you can certainly look at the technique and see if you can do something similar.
Thank you for the reply.
I did have a quick look and while it covers exporting to HTML using a lot of CSS, I cannot use CSS as this HTML is going straight into an email client that ignores style tags.
Looking at my code above, and comparing with the stackoverflow link in my reply, would you have any suggestions of how to write that?
You've got two basic methods. The first is to simply replace the generic tags with tags that have style applied. The second is dynamically creating the table by stepping through the data:
Awesome. Thank you for the reply!
I have amended my initial code and my script now looks like this...
$smtpServer = "x.x.x.x"
$message = New-Object System.Net.Mail.MailMessage $smtpfrom, $smtpto
$summ = Import-Csv -Path 'C:\folder\file.csv'
$message.Body = @"
$finalHTML = $message.Body -replace "
You must be logged in to reply to this topic.