# encoding: ascii # api: powershell # title: Send-HTMLFormattedEmail # description: Use this function to send an HTML Formatted Email that is based on an XSLT template. This function is based on a blog post by Erik McCarty (http://ewmccarty.spaces.live.com). # version: 1.0 # type: function # author: Enter your zip code here # license: CC0 # function: Send-HTMLFormattedEmail # x-poshcode-id: 3949 # x-archived: 2013-05-20T17:34:31 # x-published: 2013-02-14T15:28:00 # # #------------------------------------------------- # Send-HTMLFormattedEmail #------------------------------------------------- # Usage: Used to send an HTML Formatted Email that is based on an XSLT template. #------------------------------------------------- function Send-HTMLFormattedEmail{ param ( [string] $To, [string] $ToDisName, [string] $BCC, [string] $From, [string] $FromDisName, [string] $Subject, [string] $Content, [string] $Relay, [string] $XSLPath) try { # Load XSL Argument List $XSLArg = New-Object System.Xml.Xsl.XsltArgumentList $XSLArg.Clear() $XSLArg.AddParam("To", $Null, $ToDisName) $XSLArg.AddParam("Content", $Null, $Content) # Load Documents $BaseXMLDoc = New-Object System.Xml.XmlDocument $BaseXMLDoc.LoadXml("") $XSLTrans = New-Object System.Xml.Xsl.XslCompiledTransform $XSLTrans.Load($XSLPath) #Perform XSL Transform $FinalXMLDoc = New-Object System.Xml.XmlDocument $MemStream = New-Object System.IO.MemoryStream $XMLWriter = [System.Xml.XmlWriter]::Create($MemStream) $XSLTrans.Transform($BaseXMLDoc, $XSLArg, $XMLWriter) $XMLWriter.Flush() $MemStream.Position = 0 # Load the results $FinalXMLDoc.Load($MemStream) $Body = $FinalXMLDoc.Get_OuterXML() # Create from, To, BCC and the message strucures $MessFrom = New-Object System.Net.Mail.MailAddress $From, $FromDisName $MessTo = New-Object System.Net.Mail.Mailaddress $To $MessBCC = New-Object System.Net.Mail.Mailaddress $BCC $Message = New-Object System.Net.Mail.MailMessage $MessFrom, $MessTo # Populate message $Message.Subject = $Subject $Message.Body = $Body $Message.IsBodyHTML = $True # Add BCC $Message.BCC.Add($MessBCC) # Create SMTP Client $Client = New-Object System.Net.Mail.SmtpClient $Relay # Send The Message $Client.Send($Message) } catch { return $Error[0] } } ### XSLT Template Example My First Formatted Email

Dear ,

Please do not respond to this email!
An automated system sent this email, if any point you have any questions or concerns please open a help desk ticket.

Many thanks from your:
Really Cool IT Team