So, I have been working on building a PowerShell based notification engine for a favorite MSFT product of mine called Certificate Lifecycle Manager (kidding!). Anyhow, I wanted to make the emails pretty (after all, everyone loves pretty emails). To do this, I figured the best method was send out HTML formatted emails. However, I did not want to have the email layout necessarily embedded within my PowerShell code.
Employing Google, I searched around. Sadly, at first I really didn’t see anything that peaked my interested. Almost ready to write the code myself, I then found a really great blog posting by Erik McCarty which had some code that did almost exactly what I wanted (Hurray!).
Considering that I like sharing, below is the function that came about from that posting and the relevant XSLT example. Additionally, I posted this on PoshCode.
**Updated**
I made a number of improvements to the function that I previously posted. The function is now a module which has help, can accept an address list, better error handling, etc. This module can be found on PoshCode. To use this module, just import the module into your PowerShell session using the Import-Module cmdlet (use PowerShell v2.0 CTP3 or greater).
Once you have the module imported, you can make use of the Send-HTMLFormattedEmail cmdlet. For example:
Send-HTMLFormattedEmail -To bob@aol.com -ToDisName “Bob Barker” -From thepope@vaticancity.va -FromDisName “The Pope” -Subject “Golf Time!” -Content “I really want to play this Sunday, are you up for 18 holes?” -Relay smtp.popemail.com -XSLPath “C:templatesholymailtemplate.xsl”
Again, the format for the XSL template should be as follows:
Pope Mail
Dear
,
Many thanks from your:
Holiness
If you like this, check out some other posts from Tyson:
- When a computer science degree matters, and when it doesn’t
- Since when did cloud computing become/need a manifesto?
- Why would one phish using a Certificate Authority (CA) as bait?
- Would I trust you, if everyone else trusted you?
- Here is a good question: Is scripting programming or just systems administration?
- PowerShell boy and the case of the missing cmdlets!
- Fun with PowerShell 2.0 Eventing!
- Creating a custom 404 page to handle link redirection for ASP.NET web applications
Or if you want, you can also check out some of Tyson’s latest publications:
- Windows PowerShell Unleashed (2nd Edition)
- Windows Server 2008 Unleashed (Yes, I did help on this book)
Lastly, visit the Microsoft Subnet for more news, blogs, and opinions from around the Internet. Or, sign up for the bi-weekly Microsoft newsletter. (Click on News/Microsoft News Alert)




