PowerShell: Sending Emails Securely (via SSL)

Here is a sample that uses the live.com freemailer (formally called Hotmail) which does require a secure connection:

PS> Send-MailMessage -Body 'My mail message can contain special characters: äöüß' -From youraccountname@hotmail.com -to someone@somewhere.com -Credential youraccountname@hotmail.com -SmtpServer smtp.live.com -Subject 'Sending Mail from PowerShell' -Encoding UTF8 -UseSsl

Note that PowerShell v3 Send-MailMessage accepts UTF8 directly so you no longer need to submit the awkward ([System.Text.Encoding]::UTF8).

There are plenty of websites that list SMTP server URLs for your favorite provider: http://www.e-eeasy.com/SMTPServerList.aspx.

Leave a Reply

Your email address will not be published.