Sending Mails With Outlook

by Jan 4, 2011

You can use PowerShell to automatically prepare your e-mails and send them via Outlook. The code requires that you first launch Outlook as an application. It will not work when Outlook has not yet been started.

Start-Process Outlook
$o = New-Object -com Outlook.Application
$mail = $o.CreateItem(0)
$mail.subject = "Test message"
$mail.body = "First line`nSecond Line`nThird line"
$mail.To = "tobias.weltner@email.de"
#$mail.Attachments.Add("C:\somefile.txt")
$mail.Send()
$o.Quit()

Twitter This Tip!
ReTweet this Tip!