Ubuntu – Configure sSMTP with Gmail, in Ubuntu 12.04 LTS

gmailPROXYsmtp

I am trying to get my hands on a good command line email tool for Ubuntu so that I can send simple emails may be even attach files through the terminal or simple bash scripts. My ssmtp.conf file looks something like this right now:

#
# Config file for sSMTP sendmail
#
# The person who gets all mail for userids < 1000
# Make this empty to disable rewriting.
root=myusername@gmail.com

# The place where the mail goes. The actual machine name is required no 
# MX records are consulted. Commonly mailhosts are named mail.domain.com
mailhub=smtp.gmail.com:587

# Where will the mail seem to come from?
rewriteDomain=gmail.com

# The full hostname
hostname=myusername@gmail.com
AuthUser=myusername
AuthPass=mypassword
UseSTARTTLS=YES 
# Are users allowed to set their own From: address?
# YES - Allow the user to specify their own From: address
# NO - Use the system generated From: address
FromLineOverride=YES

I also added alias in the revaliases file as follows:

root:myusername@gmail.com:smtp.gmail.com:587
localusername:myusername@gmail.com:smtp.gmail.com:587

I am behind a proxy server which works when i set an automatic proxy configuration URL and my system proxy settings are set according to the automatic proxy configuration URL.

However when I run sSMTP from terminal using:

sudo ssmtp someone@example.com
hello world 

Then pressing ctrl+d, I get:

ssmtp: Cannot open smtp.gmail.com:587

The title is the question.

Best Answer

mailhub=smtp.gmail.com:465

The port is wrong. Your aliases need updating too.

Gmail only really allows SSL emails from remote hosts, other connections usually don't work. Enable SSL and use port 465.

If that doesn't work verify connectivity with telnet:

telnet smtp.gmail.com:465 it should work, and return gibberish.

Related Question