Search code examples
phpubuntugmailssmtp

How to fix error with sending email using gmail?


I want to send email in my php/laravel app in ubuntu 18 under Digital Ocean and I found this https://semantiko.com/how-to-fix-php-mail-function-on-ubuntu-server/ article I filled related config files and send several email and I found in console:

grep -riI ssmtp /var/log
...
/var/log/mail.log:Oct 24 14:05:22 nsn-do-lamp sSMTP[16500]: SSL connection using ECDHE_RSA_CHACHA20_POLY1305
/var/log/mail.log:Oct 24 14:05:22 nsn-do-lamp sSMTP[16500]: Authorization failed (534 5.7.14  https://support.google.com/mail/answer/78754 b5-v6sm5187045wrr.94 - gsmtp)
/var/log/mail.log:Oct 24 14:05:23 nsn-do-lamp sSMTP[16502]: Creating SSL connection to host
/var/log/mail.log:Oct 24 14:05:23 nsn-do-lamp sSMTP[16502]: SSL connection using ECDHE_RSA_CHACHA20_POLY1305
/var/log/mail.log:Oct 24 14:05:23 nsn-do-lamp sSMTP[16502]: Authorization failed (534 5.7.14  https://support.google.com/mail/answer/78754 t198-v6sm6776812wmd.9 - gsmtp)
/var/log/dpkg.log:2018-10-24 05:27:56 install ssmtp:amd64 <none> 2.64-8ubuntu2
/var/log/dpkg.log:2018-10-24 05:27:56 status half-installed ssmtp:amd64 2.64-8ubuntu2
/var/log/dpkg.log:2018-10-24 05:27:56 status unpacked ssmtp:amd64 2.64-8ubuntu2
/var/log/dpkg.log:2018-10-24 05:27:56 status unpacked ssmtp:amd64 2.64-8ubuntu2
/var/log/dpkg.log:2018-10-24 05:27:56 configure ssmtp:amd64 2.64-8ubuntu2 <none>
/var/log/dpkg.log:2018-10-24 05:27:56 status unpacked ssmtp:amd64 2.64-8ubuntu2
/var/log/dpkg.log:2018-10-24 05:27:56 status unpacked ssmtp:amd64 2.64-8ubuntu2
/var/log/dpkg.log:2018-10-24 05:27:56 status unpacked ssmtp:amd64 2.64-8ubuntu2
/var/log/dpkg.log:2018-10-24 05:27:56 status half-configured ssmtp:amd64 2.64-8ubuntu2
/var/log/dpkg.log:2018-10-24 05:27:56 status installed ssmtp:amd64 2.64-8ubuntu2
/var/log/syslog.1:Oct 24 05:34:07 nsn-do-lamp sSMTP[10100]: Creating SSL connection to host
/var/log/syslog.1:Oct 24 05:34:07 nsn-do-lamp sSMTP[10100]: SSL connection using ECDHE_RSA_CHACHA20_POLY1305
/var/log/syslog.1:Oct 24 05:34:07 nsn-do-lamp sSMTP[10100]: Authorization failed (534 5.7.9  https://support.google.com/mail/?p=WebLoginRequired 130-v6sm4756430wmn.7 - gsmtp)

and under my account in https://mail.google.com I found email :

Sign-in attempt was blocked
[email protected]
Someone just used your password to try to sign in to your account from a non-Google app. Google blocked them, but you should check what happened. Review your account activity to make sure no one else has access.
CHECK ACTIVITY

Clicking on "CHECK ACTIVITY" button next page was opened https://i.sstatic.net/9a3pz.jpg and I want TO PERMIT my account or me, to be used so I click on "NO, SECURE ACCOUNT" and next page is opened https://i.sstatic.net/zyvTs.jpg

that was rather strange for me, as I do not need to change the password. I want to permit mail service to use my gmail.com account.

Can you say what is wrong ?
Did I misunderstand gmail messages ?

MODIFIED BLOCK # 2 I tried to follow the provided link and I opened the next instructions :

Use this setting when you want to ensure that access by a less secure app is unavailable to all. Sign in to your Google Admin console. Sign in using an administrator account, not your current account [email protected]

... Who is my administrator? Quick definition: A person who manages Google services or devices for a company, school, or group. Someone in your company, school, or group Your current account, [email protected], isn’t managed by an administrator. The account isn’t associated with any company, school, or group. Instead, it’s a free Google Account that you can manage yourself.

But reading the docs I missed as I am free Google Account is there is a way to make myself as administrator? If yes, please point where and how ?

MODIFIED BLOCK # 3: In my conf files 587 port is used: sudo nano /etc/ssmtp/ssmtp.conf :

[email protected]
mailhub=smtp.gmail.com:587
hostname=smtp.gmail.com:587
UseSTARTTLS=YES
[email protected]
AuthPass=MYPASSWORD
FromLineOverride=YES
UseTLS=YES

sudo nano /etc/ssmtp/revaliases :

root:[email protected]:smtp.gmail.com:587

After modifing of thesae files I run command service apache2 restart

and testing sending email I do not recieve emails on my email and I see a lot of “Authorization failed” errors in next log

grep -riI ssmtp /var/log
var/log/syslog.1:Oct 30 00:34:04 nsn-do-lamp sSMTP[24892]: Creating SSL connection to host
/var/log/syslog.1:Oct 30 00:34:04 nsn-do-lamp sSMTP[24892]: SSL connection using ECDHE_RSA_CHACHA20_POLY1305
/var/log/syslog.1:Oct 30 00:34:05 nsn-do-lamp sSMTP[24892]: Authorization failed (534 5.7.14  https://support.google.com/mail/answer/78754 y76-v6sm12958494wmd.37 - gsmtp)
/var/log/syslog.1:Oct 30 01:34:04 nsn-do-lamp sSMTP[25660]: Creating SSL connection to host
/var/log/syslog.1:Oct 30 01:34:04 nsn-do-lamp sSMTP[25660]: SSL connection using ECDHE_RSA_CHACHA20_POLY1305
/var/log/syslog.1:Oct 30 01:34:04 nsn-do-lamp sSMTP[25660]: Authorization failed (534 5.7.14  https://support.google.com/mail/answer/78754 60-v6sm16580038wra.35 - gsmtp)
/var/log/syslog.1:Oct 30 02:34:05 nsn-do-lamp sSMTP[26444]: Creating SSL connection to host
/var/log/syslog.1:Oct 30 02:34:05 nsn-do-lamp sSMTP[26444]: SSL connection using ECDHE_RSA_CHACHA20_POLY1305
/var/log/syslog.1:Oct 30 02:34:05 nsn-do-lamp sSMTP[26444]: Authorization failed (534 5.7.14  https://support.google.com/mail/answer/78754 t16-v6sm274794wrr.12 - gsmtp)
/var/log/syslog.1:Oct 30 03:34:06 nsn-do-lamp sSMTP[27101]: Creating SSL connection to host
/var/log/syslog.1:Oct 30 03:34:07 nsn-do-lamp sSMTP[27101]: SSL connection using ECDHE_RSA_CHACHA20_POLY1305
/var/log/syslog.1:Oct 30 03:34:07 nsn-do-lamp sSMTP[27101]: Authorization failed (534 5.7.14  https://support.google.com/mail/answer/78754 m16-v6sm13164091wmd.35 - gsmtp)
/var/log/syslog.1:Oct 30 04:34:04 nsn-do-lamp sSMTP[27852]: Creating SSL connection to host
/var/log/syslog.1:Oct 30 04:34:04 nsn-do-lamp sSMTP[27852]: SSL connection using ECDHE_RSA_CHACHA20_POLY1305
/var/log/syslog.1:Oct 30 04:34:05 nsn-do-lamp sSMTP[27852]: Authorization failed (534 5.7.14  https://support.google.com/mail/answer/78754 143-v6sm17450782wmv.6 - gsmtp)
/var/log/syslog.1:Oct 30 05:34:04 nsn-do-lamp sSMTP[28734]: Creating SSL connection to host
/var/log/syslog.1:Oct 30 05:34:04 nsn-do-lamp sSMTP[28734]: SSL connection using ECDHE_RSA_CHACHA20_POLY1305
/var/log/syslog.1:Oct 30 05:34:04 nsn-do-lamp sSMTP[28734]: Authorization failed (534 5.7.14  https://support.google.com/mail/answer/78754 b5-v6sm1822874wrf.15 - gsmtp)

1) Can be some more services I need to restart apart apache2

2) It seems to me that these log messages are not last, as running :

 # date
Tue Oct 30 12:02:40 UTC 2018

I see time difference, like that were no last message rows Is there is a way to clear ssmtp logs?

3) Which is safe way to restart ubuntu 18 under Digital Ocean, without droplet damage ? In some case that I am not sure if have I to restart some service I prefer to restart the system...

MODIFIED BLOCK # 4: Thank you for your feedback! I tried to follow you instructions : 1) I activated two factor authentication : https://i.sstatic.net/174Zb.jpg. But if have I do to something with these apps?

2) I got password https://i.sstatic.net/S60UJ.jpg in format XXXX XXXX XXXX XXXX

3) after password creation I got next page https://i.sstatic.net/9NJ38.jpg:

4) You mentioned

“use the app password in your .env file”

which must be name of var of this password? Like in

AuthPass=MYPASSWORD # password without spaces in it?

in /etc/ssmtp/ssmtp.conf or some other name ? Only this new password generated I need ?

Thanks!


Solution

  • We've had similar problems when we used some "fresh" gmail addresses from our Google Apps for work account. Seems that Google has some kind of heuristic running for new addresses that block app access from unknown apps.

    Our solution was to enable 2-factor-authentication and subsequently generate an app password. Steps: