7

I have the following ssmtp.conf file:

[email protected]
mailhub=smtp.gmail.com:587
hostname=ed424cef9b52
UseTLS=Yes
UseStartTTLS=Yes
AuthMethod=LOGIN
AuthUser=test
AuthPass=test
FromLineOverride=yes
TLS_CA_File=/etc/ssl/certs/ca-certificates.crt

I can connect to 587 gmail port:

telnet smtp.gmail.com 587
Trying 64.233.186.109...
Connected to gmail-smtp-msa.l.google.com.

But when I try to send mail:

/usr/sbin/ssmtp -v [email protected] < qq
ssmtp: Cannot open smtp.gmail.com:587

echo test | mailx  -s "testing ssmtp setup" [email protected]
send-mail: Cannot open smtp.gmail.com:587
Can't send mail: sendmail process failed with error code 1
SDsolar
  • 1,699
  • 3
  • 15
  • 26
sebelk
  • 4,209
  • 10
  • 35
  • 54

1 Answers1

10

The proper port is 465

Simplest way to send mail with image attachment from command line using gmail?


EXCERPT:

Install ssmtp with the following commands:

sudo apt-get update
sudo apt-get install ssmtp

Then go into /etc/ssmtp and edit ssmtp.conf to look like this:

[email protected]
mailhub=smtp.gmail.com:465
FromLineOverride=YES
[email protected]
AuthPass=testing123
UseTLS=YES

Send a one-liner like so:

echo "Testing...1...2...3" | ssmtp [email protected]

Send a formatted text file like so:

cat mymessage | ssmtp [email protected]

Where mymessage can be formatted to have lines for TO: and SUBJECT: and the body.

TO: [email protected]
SUBJECT: Testing
     -blank line-
Message body goes here....
SDsolar
  • 1,699
  • 3
  • 15
  • 26
  • 1
    And I got: ssmtp: Authorization failed (534 5.7.9 https://support.google.com/mail/?p=InvalidSecondFactor s3sm1189087qkj.118 - gsmtp) Is this because google turned on two-factor authentication? – mpersico Oct 20 '21 at 16:38
  • 1
    Fixed: https://stackoverflow.com/questions/26736062/sending-email-fails-when-two-factor-authentication-is-on-for-gmail – mpersico Oct 20 '21 at 16:43