Recent Articles

How to Send Email To SMTP Server From Command Line

There is a easy way to test your SMTP server from the Windows command line or Linux shell. The email system was created before the advancement of the web browser and the internet so you can imagine the network protocol used is very simple. All you need is to connect to a specific port and send in a series of text commands.

SMTP runs on the well-known port 25. From your command prompt, you should be able to telnet to that port and send a few text commands unless your administrator has explicitly blocked you. In this example, I'm going to send an email to a Hotmail account directly from my computer.

From your command line, type the following command. If your admin allows you to telnet to port 25, you should be seeing the welcome message below.

C:\>telnet mx1.hotmail.com 25

220 bay0-mc2-f11.bay0.hotmail.com Sending unsolicited commercial or bulk e-mail to Microsoft's computer network is prohibited. Other restrictions are found at http://privacy.msn.com/Anti-spam/. Violations will result in use of equipment located in California and other states. Tue, 31 Jul 2007 04:49:17 -0700

Type HELO to introduce yourself. The remote machine will reply and greet you.

HELO localmailer
250 bay0-mc2-f11.bay0.hotmail.com (3.3.3.1) Hello [208.101.2.197]

If your SMTP server is expecting authentication, you can pass the username and password in Base64 encoded following the AUTH LOGIN command. In the example below, the "d2VsZG9u" is the username and "dzNsZDBu" is the password in Base64 encoding:

AUTH LOGIN
334 VXNlcm5hbWU6
d2VsZG9u
334 UGFzc3dvcmQ6
dzNsZDBu
235 2.0.0 OK Authenticated

Now, tell the server where you're sending the email from.

MAIL FROM: john@example.com
250 john@example.com....Sender OK

Specify a recipient email to send the test email to. Enter a valid Hotmail address (yours preferably so you can check the results).

RCPT TO: somebody@hotmail.com
250 somebody@hotmail.com

Type DATA to begin entering the subject and the rest of the email body.

DATA
354 Start mail input; end with .

 

Enter a single period (.) on a new line to indicate end of message.

.
250 <BAY0-MC2-F11C2LCUgx001ff08b@bay0-mc2-f11.bay0.hotmail.com> Queued mail for delivery

That's all. You can now disconnect the session by typing QUIT.

QUIT
221 bay0-mc2-f11.bay0.hotmail.com Service closing transmission channel
Connection to host lost.

There you go, if you entered all the commands correctly as shown, you should now have received an email in your Hotmail account.

Subject: This is a test

Please disregard this test email.

Thanks,