Sending SMTP Mail from Windows Using PowerShell

When working from the Windows command line, you can do a quick test to validate your SMTP connectivity using PowerShell:

 

c:\> Powershell -executionpolicy bypass

PS c:\> Send-MailMessage –to <TO> –from <FROM> –subject "testing123" –body "this is a test" –smtpserver <SMTPServer> -port 25

And if the mail server is accessed over TLS/SSL with SMTP authentication enabled:

PS c:\> Send-MailMessage –to <TO> –from <FROM> –subject "testing456" –body "this is a secure test" –smtpserver <SMTPServer> -port 587 -UseSsl -Credential (Get-Credential)

This is easier than going down to telnet, which is typically not installed on a modern Windows host:

CMD> telnet <SMTPServer> 25


EHLO <CLIENTHOST>

MAIL FROM: <FROM>

RCPT TO: <TO>

DATA

Subject: testing123

this is a test


.

QUIT

 

If you need to test authenticated SMTP from a Linux host, see my article here.