Pages

Tuesday, May 8, 2012

Send mail from Gmail using command line

I tested it on Windows.

What you need:
stunnel 
telnet

Install stunnel. Run it.

Right click on icon in System Tray. Click on Edit stunnel.conf. Uncomment the lines corresponding to [gmail-smtp] and make these changes:


[gmail-smtp]
client = yes
accept = 127.0.0.1:2301
connect = smtp.gmail.com:465

Right click on icon in System Tray. Click on Reload stunnel.conf.

Now from command prompt type: telnet localhost 2301
If telnet is not available see the next post on how to enable it.

If all goes well you should see the following in the telnet window:

220 mx.google.com ESMTP

Type:
HELO google
250 mx.google.com at your service

Type:
AUTH LOGIN
334 VXNlcm5hbWU6
This is Base64 for:
334 Username:

Type your username in Base64. Use this website for performing the conversion.

You'll now see
334 UGFzc3dvcmQ6
which is Base64 for (you guessed it!) Password:

If the u/n pwd is accepted you'll see:
xxxxxx 2.7.0 Accepted

You're in!!

Type
MAIL FROM:<username@gmail.com>
250 2.1.0 OK 

The angular brackets are important.

RCPT TO:<friend@school.edu>
250 2.1.5 OK

DATA
354  Go ahead
From: User <username@gmail.com>
To: Friend <friend@school.edu>
Subject: Hello!
Body
.
250 2.0.0 OK

End body with a . in a new line

QUIT
221 2.0.0 closing connection


Pretty cool right?

EDIT:
For doing  AUTH PLAIN use:
Python code:
from base64 import b64encode
b64encode('authorization-id' + '\0' + 'authentication-id' + '\0' + 'passwd')

The client may leave the authorization-id empty to indicate that it is the same as the authentication identity

For doing AUTH CRAM-MD5 use the following code:
http://www.net-track.ch/opensource/cmd5/

No comments:

Post a Comment