sunmingtao / sample-code

3 stars 4 forks source link

ssmtp: Cannot open mail:25 #180

Closed sunmingtao closed 4 years ago

sunmingtao commented 4 years ago

sudo nano /etc/ssmtp/ssmtp.conf

# The user that gets all the mails (UID < 1000, usually the admin)
root=username@gmail.com

# The mail server (where the mail is sent to), both port 465 or 587 should be acceptable
# See also https://support.google.com/mail/answer/78799
mailhub=smtp.gmail.com:587

# The address where the mail appears to come from for user authentication.
rewriteDomain=gmail.com

# The full hostname.  Must be correctly formed, fully qualified domain name or GMail will reject connection.
hostname=localhost

# Use SSL/TLS before starting negotiation
TLS_CA_FILE=/etc/ssl/certs/ca-certificates.crt
UseTLS=Yes
UseSTARTTLS=Yes

# Username/Password
AuthUser=username
AuthPass=<password> or <app password (see below)>
AuthMethod=LOGIN

# Email 'From header's can override the default domain?
FromLineOverride=yes

https://wiki.archlinux.org/index.php/SSMTP

If getting error of "invalid credentials", under the Gmail Account settings ,there would be an option saying "Allow less secure Apps ", turn it ON.

To test ssmtp myemailaddress@gmail.com < msg.txt

sunmingtao commented 3 years ago

If getting

ssmtp: Authorization failed (534 5.7.9  https://support.google.com/mail/?p=InvalidSecondFactor m64sm11949935pga.55 - gsmtp)

Then follow https://support.google.com/mail/?p=InvalidSecondFactor to generate an app password