How to Test SMTP Email Sending from Windows Server 2008 Using Command Line Tools


3 views

When configuring email services on Windows Server 2008, you'll often need to verify SMTP settings, authentication, and firewall rules. The challenge is finding a simple way to send test emails without writing custom code or installing heavy email clients.

Windows Server 2008 includes telnet client (though disabled by default), which can directly communicate with SMTP servers:

# Enable telnet client first:
dism /online /Enable-Feature /FeatureName:TelnetClient

# Then connect to SMTP server:
telnet mail.yourserver.com 25

Once connected, you can manually enter SMTP commands like:

EHLO yourdomain.com
AUTH LOGIN
[base64-encoded username]
[base64-encoded password]
MAIL FROM: test@yourdomain.com
RCPT TO: recipient@example.com
DATA
Subject: Test Email
This is a test message.
.
QUIT

For more automation, PowerShell provides the Send-MailMessage cmdlet (requires PowerShell 2.0+):

Send-MailMessage -SmtpServer "smtp.yourdomain.com" 
    -Port 587 
    -UseSsl 
    -Credential (Get-Credential) 
    -From "sender@yourdomain.com" 
    -To "recipient@example.com" 
    -Subject "SMTP Test" 
    -Body "Testing server SMTP configuration"

For more comprehensive testing, consider these lightweight tools:

  1. Blat - Simple command-line SMTP mailer:
    blat -to recipient@example.com -server smtp.yourdomain.com -f sender@yourdomain.com -port 587 -u username -pw password -subject "Test" -body "Message"
    
  2. swaks - Swiss Army Knife for SMTP testing (requires Perl)

When verifying your SMTP configuration, test these critical cases:

  • Plain authentication vs SSL/TLS
  • Different ports (25, 465, 587)
  • Relay restrictions
  • SPF/DKIM compliance

For debugging connection issues, combine with:

Test-NetConnection smtp.yourdomain.com -Port 587

For quick SMTP server connectivity tests without authentication, telnet remains a classic tool:

telnet your.smtp.server.com 25
HELO testdomain.com
MAIL FROM: <test@yourdomain.com>
RCPT TO: <recipient@example.com>
DATA
Subject: SMTP Test
This is a test email body.
.
QUIT

Windows Server 2008 includes PowerShell 2.0 which offers built-in email capabilities:

Send-MailMessage -SmtpServer "your.smtp.server.com" 
-Port 587 
-UseSsl 
-Credential (Get-Credential) 
-From "sender@domain.com" 
-To "recipient@example.com" 
-Subject "SMTP Test Email" 
-Body "Testing server email configuration"

Many Windows admins swear by this free command-line email tool:

blat -to recipient@example.com -server smtp.yourdomain.com:587 
-subject "Test Email" -body "Testing SMTP configuration" 
-u yourusername -pw yourpassword -f sender@yourdomain.com

When testing fails, check these key elements:

  • Verify port numbers (25/465/587)
  • Confirm TLS/SSL requirements
  • Check if your IP needs whitelisting
  • Validate authentication method (PLAIN/LOGIN/NTLM)

If Python is available, this provides more flexibility:

python -c "import smtplib; server=smtplib.SMTP('smtp.yourdomain.com',587); server.starttls(); server.login('user','pass'); server.sendmail('from@domain.com','to@domain.com','Subject: Test\\n\\nBody'); server.quit()"