I used to use blat to send email in powershell 1 but in powershell v2 we have a nice Send-MailMessage cmdlet
Carriage Return New Line does not show in Outlook
Line breaks are removed in posts made in plain text format in Outlook
Method 1. Disable the feature that removes extra line breaks
This method disables the feature for all plain text items. To do this, follow these steps:
For Outlook 2013 and Outlook 2010:
Open Outlook.
On the File tab, click Options.
In the Options dialog, click Mail.
In the Message format section, clear the Remove extra line breaks in plain text messages check box.
Click OK.
For Outlook 2007 or earlier versions:
Open Outlook.
On the Tools menu, click Options.
On the Preferences tab, click the E-mail Options button.
Click to clear the Remove extra line breaks in plain text messages check box.
Click OK two times.
Method 2. Use HTML or Rich Text format
You can use HTML or Rich Text formats when you create new items. Or you can change existing posts to these formats.
Sending a HTML email
$To = "Kevin <k@blah.com>" $From = "AD Reporting <ADReporting@blah.com>" $smtpServer = "mail.blah.com" $message =Get-QADGroupMember "domain admins" | select name, samaccountname, lastlogontimestamp | ConvertTo-Html | Out-String Send-MailMessage -From $From -To $To -SmtpServer $smtpServer -Subject test -Body $message -BodyAsHtml
This time prefix the HTML with a header
$preHTMLMessage = "Please go through this list and look for any unnecessary accounts <H2>Domain Admins.</H2>" $postHTMLMessage = "<br> This script was run by " + $env:username + " on " + $env:COMPUTERNAME + " and ran for $([Math]::Round($ElapsedTime.TotalMinutes,0)) Minutes" $message = Get-QADGroupMember "domain admins" | select name, samaccountname, lastlogontimestamp | ConvertTo-Html -preContent $preHTMLMessage -PostContent $postHTMLMessage | Out-String Send-MailMessage -From $From -To $To -SmtpServer $smtpServer -Subject test -Body $message -BodyAsHtml
Nice page with some good examples how to change background add styles etc.
http://technet.microsoft.com/en-us/library/ff730936.aspx
Sending an email via Gmail
Need a cleaner way to store password
$To = "foo@gmail.com" $From = "reporting@blah.com" $BadPassword = "badcleartextpassword" $Subject = "Test" $Body = "Test email via gmail " #$SMTPMessage = New-Object System.Net.Mail.MailMessage($From,$To,$Subject,$HTML) $SMTPMessage = New-Object System.Net.Mail.MailMessage $SMTPMessage.From = $From Foreach ($email in $To) { $SMTPMessage.To.Add($email) } $SMTPMessage.Subject = $Subject $SMTPMessage.body = $HTML $SMTPServer = "smtp.gmail.com" $SMTPClient = New-Object Net.Mail.SmtpClient($SmtpServer, 587) $SMTPClient.EnableSsl = $true $SMTPClient.Credentials = New-Object System.Net.NetworkCredential($From, $BadPassword); $SMTPClient.Send($SMTPMessage)