Search This Blog

Wednesday, April 3, 2013

Send an e-mail using command line



Here is a quick note how to send an e-mail using command line interface.

First Telnet to the mail server using port 25 and then run the following commands:

helo <SMTP_SERVER_DOMAIN>
AUTH LOGIN
<BASE64 USERNAME@DOMAIN>
<BASE64 PASSWORD>
mail from:<USER@DOMAIN>
rcpt to: <USER@DOMAIN>
data
From: <USER@DOMAIN>
Subject: test mail from command line

this is test message number 1
sent from my router
.

Don’t forget the “.” In the end

The authentication section is required for SMTP servers which prevent relay through the use of authentication. The username@domain and password should be typed in base64 which can be encoded using the following site:  http://www.base64encode.org/

And here is an example with Bezeq International SMTP server:
MRTR#telnet out.bezeqint.net 25         
Translating "out.bezeqint.net"...domain server (192.115.106.35)

Translating "out.bezeqint.net"...domain server (192.115.106.35) [OK]
Trying out.bezeqint.net (192.115.187.185, 25)... Open
220 out7.bezeqint.net ESMTP Postfix at your service - please...
helo bezeqint.net
250 out7.bezeqint.net
AUTH LOGIN
334 VXNlcm5hbWU6
<BASE64 USERNAME@DOMAIN>
334 UGFzc3dvcmQ6
<BASE64 PASSWORD>
235 2.7.0 Authentication successful
mail from:username1@bezeqint.net
rcpt to:username2@domain.net
data
From:username1@bezeqint.net
Subject: test mail from command line

this is test message number 1
sent from my router
.
250 2.1.0 Ok
250 2.1.5 Ok
354 End data with <CR><LF>.<CR><LF>
250 2.0.0 Ok: queued as 2229F5E2AF3

The following output is from Cisco IOS router.

1 comment:

  1. Nice project. To encode into base64 the username@domain and password, you can check the following link
    url-decode.com/tool/base64-encode where the landing page provides more tools for the simple users and developers.

    ReplyDelete