Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

Email a CSV as HTML email

$
0
0

I have this section of code that is trying to convert a CSV file into a HTML email.  It converts to a HTML file fine, I out-put the file and view in a browser, but the string and the email is the raw HTML data.  I assume this is because I haven’t created the string correctly to insert into the email body.  How it looks in the console and the email is the text output at the bottom.  So what have I got wrong?

$htmlformat  ='<title>Matching AD accounts from HR leavers list</title>'

$htmlformat+='<style type="text/css">'

$htmlformat+='BODY{background-color:#FFFFFB;color:#00005C;font-family:Arial,sans-serif;font-size:15px;}'

$htmlformat+='TABLE{border-width: 3px;border-style: solid;border-color: black;border-collapse: collapse;}'

$htmlformat+='TH{border-width: 1px;padding: 3px;border-style: solid;border-color: black;background-color:#D6D6F5}'

$htmlformat+='TD{border-width: 1px;padding: 8px;border-style: solid;border-color: black;background-color:#FFFFCC}'

$htmlformat+='</style>'

$EmailBody=Import-Csv-PathC:\PurgeUserRecords\FromHR\LeftIn-$Month.csv|ConvertTo-Html-Head$htmlformat-Body'<h1>Matching AD accounts from HR leavers list </h1>'

Send-MailMessage-Fromadmin@**.**.uk-Subject"HR reported these users as having left CYC in $date"-Tojonathan.hall@**.**.uk-Body$EmailBody-SmtpServer **.**.**.uk

 

 $EmailBody looks like this on the console

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<title>Matching AD accounts from HR leavers list</title><style type="text/css">BODY{background-color:#FFFFFB;color:#00005C;font-family:Arial,sans-serif;font-size:15px;}TABLE{border-width: 3px;border-style: solid;border-color: bla

ck;border-collapse: collapse;}TH{border-width: 1px;padding: 3px;border-style: solid;border-color: black;background-color:#D6D6F5}TD{border-width: 1px;padding: 8px;border-style: solid;border-color: black;background-color:#FFFFCC}<

/style>

</head><body>

<h1>Matching AD accounts from HR leavers list </h1>

<table>

<colgroup><col/><col/><col/><col/><col/><col/><col/><col/><col/></colgroup>

<tr><th>DisplayName</th><th>SamAccountName</th><th>EmployeeNumber</th><th>DC01</th><th>DC02</th><th>DC03</th><th>DC04</th><th>LastTrueLogon</th><th>Manager</th></tr>

<tr><td>Young, Sarah</td><td>casepsy</td><td>32081A</td><td>05/12/2014 18:30:06</td><td>13/07/2014 18:32:06</td><td>28/08/2014 11:50:38</td><td>05/12/2014 18:29:27</td><td>12/05/2014 18:30:06</td><td></td></tr>

<tr><td>Mansell, Amanda</td><td>ccsswam</td><td>39670</td><td>15/02/2015 10:39:55</td><td>20/02/2015 11:26:53</td><td>15/02/2015 10:37:17</td><td>20/02/2015 11:24:34</td><td>02/20/2015 11:26:53</td><td></td></tr>

<tr><td>Brown, Sharon(Housing)</td><td>chscasb</td><td>37754</td><td>30/01/2015 12:32:21</td><td>30/01/2015 12:31:37</td><td>29/01/2015 11:27:12</td><td>30/01/2015 12:31:41</td><td>01/30/2015 12:32:21</td><td></td></tr>

<tr><td>Robinson, Louise</td><td>ddtenlr</td><td>35808</td><td>21/04/2015 11:39:18</td><td>17/04/2015 13:55:42</td><td>21/04/2015 08:42:45</td><td>21/04/2015 08:45:55</td><td>04/21/2015 11:39:18</td><td></td></tr>

<tr><td>Shield, Andy</td><td>eedhras</td><td>25841A</td><td>02/02/2015 12:09:25</td><td>03/02/2015 09:49:22</td><td>27/01/2015 16:13:56</td><td>30/01/2015 10:50:34</td><td>02/03/2015 09:49:22</td><td></td></tr>

<tr><td>Foster, Sarah</td><td>eedprsf4</td><td></td><td>Never Connected</td><td>Never Connected</td><td>Never Connected</td><td>Never Connected</td><td>Never Connected</td><td></td></tr>

<tr><td>Phillips, Lisa</td><td>rpbaslp</td><td>31707</td><td>01/03/2015 09:12:24</td><td>28/02/2015 10:12:50</td><td>01/03/2015 09:12:24</td><td>01/03/2015 09:13:10</td><td>03/01/2015 09:13:10</td><td></td></tr>

</table>

</body></html>


Viewing all articles
Browse latest Browse all 6937

Trending Articles