Thursday, February 5, 2015

HOWTO: send mail from linux using gmail


Simplest way with minimal setup is sendemail utility:

# sudo apt-get install sendemail
# sendemail -vvv -f bearrailgun@gmail.com -t to@yandex.ru -u "topic" -m "The body of the message" -s smtp.gmail.com:587 -xu bearrailgun -xp mypassword

After that you will probably see:
Feb 06 00:13:21 pulsehouse sendemail[9038]: DEBUG => evalSMTPresponse() - Found SMTP error code: 534
Feb 06 00:13:21 pulsehouse sendemail[9038]: DEBUG => SMTP-AUTH: LOGIN authenticaion failed.
Feb 06 00:13:21 pulsehouse sendemail[9038]: ERROR => ERROR => SMTP-AUTH: Authentication to smtp.gmail.com:587 failed.

Check you gmail account. You will see a new mail with notification:
Google Account: sign-in attempt blocked
Let's see inside:
"...
If this was you
You can switch to an app made by Google such as Gmail to access your account (recommended) or change your settings at https://www.google.com/settings/security/lesssecureapps so that your account is no longer protected by modern security standards."
So follow this link https://www.google.com/settings/security/lesssecureapps and change Access for less secure apps to "Turn on"

Try again same sendemail command. Now works!
Feb 06 00:15:18 pulsehouse sendemail[9055]: Email was sent successfully!  From: <bearrailgun@gmail.com> To: <to@yandex.ru> Subject: [test] Server: [smtp.gmail.com:587]

That's it.


1 comment:

  1. It was tested at Feb 05 2015, so it works. Probably you will find a lot of outdated info in inet about using ports 25 or 465. Both doesn't work.

    ReplyDelete