Send emails using the GMAIL SMTP server

Send emails from command line using the GMAIL smtp server.

Make sure you turn on Allow less secure apps settings for the email id you are going to use. (GMAIL, Account, Security, Less secure app access)

Connect using the starttls option in openssl to convert the plain connection to encrypted…

`openssl s_client -starttls smtp -connect smtp.gmail.com:587 -crlf -ign_eof`

or connect to a ssl sockect directly…

`openssl s_client -connect smtp.gmail.com:465 -crlf -ign_eof`

Type in commands
`EHLO localhost`

after that, authenticate to the server using the base64 encoded username/password

AUTH PLAIN AG15ZW1haWxAZ21haWwuY29tAG15cGFzc3dvcmQ=

to get this from the commandline:

`echo -ne ‘\00user@gmail.com\00password’ | base64 AHVzZXJAZ21haWwuY29tAHBhc3N3b3Jk`

Example session:

openssl s_client -connect smtp.gmail.com:465 -crlf -ign_eof
[... lots of openssl output ...]
220 mx.google.com ESMTP m46sm11546481eeh.9
EHLO localhost
250-mx.google.com at your service, [1.2.3.4]
250-SIZE 35882577
250-8BITMIME
250-AUTH LOGIN PLAIN XOAUTH
250 ENHANCEDSTATUSCODES
AUTH PLAIN AG5pY2UudHJ5QGdtYWlsLmNvbQBub2l0c25vdG15cGFzc3dvcmQ=
235 2.7.0 Accepted
MAIL FROM:
250 2.1.0 OK m46sm11546481eeh.9
rcpt to:
250 2.1.5 OK m46sm11546481eeh.9
DATA
354 Go ahead m46sm11546481eeh.9
Subject: it works

yay!
.
250 2.0.0 OK 1339757532 m46sm11546481eeh.9
quit
221 2.0.0 closing connection m46sm11546481eeh.9
read:errno=0

Reference: https://stackoverflow.com/questions/11046135/how-to-send-email-using-simple-smtp-commands-via-gmail

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s