72

I am trying to create e-mail alert on ssh root login so I had to install ssmtp and mail utility.

Then I configured ssmtp.conf file as follows :

# Config file for sSMTP sendmail
# The person who gets all mail for userids < 1000
# Make this empty to disable rewriting.
        #root=postmaster
        #Adding  email id to receive system information
root = rootuser@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=mail

mailhub = smtp.gmail.com:587

AuthUser=dmymail@gmail.com
AuthPass=plaintext password
UseTLS=YES
UseSTARTTLS=YES

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

# The full hostname

hostname = mailserver
# 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

as well as revaliases as follows:

# Format:       local_account:outgoing_address:mailhub
# Example: root:your_login@your.domain:mailhub.your.domain[:port]

root:rootuser@gmail.com:smtp.gmail.com:25

and I am getting this error:

send-mail: Authorization failed (534 5.7.14 https://support.google.com/mail/bin/answer.py?answer=78754 ni5sm3908366pbc.83 - gsmtp)
Can't send mail: sendmail process failed with error code 1

but it didn't work. Please help me to sort out this

squillman
  • 38,163
Connect
  • 831

7 Answers7

119

It may take more than one step to fix this issue

  1. Take the step mentioned earlier. Log into your google email account and then go to this link: https://www.google.com/settings/security/lesssecureapps and set "Access for less secure apps" to ON. Test to see if your issue is resolved. If it isn't resolved, as it wasn't for me, continue to Step #2.

  2. Go to https://support.google.com/accounts/answer/6009563 (Titled: "Password incorrect error"). This page says "There are several reasons why you might see a “Password incorrect” error (aka 534-5.7.14) when signing in to Google using third-party apps. In some cases even if you type your password correctly." This page gives 4 suggestions of things to try.

For me, the first suggestion worked:

  • Go to https://g.co/allowaccess from a different device you have previously used to access your Google account and follow the instructions.
  • Try signing in again from the blocked app.

There were three more suggestions on the page given in step #2 but I didn't try them because after going to the redacted link and following the instructions, everything began to work as it should.

masegaloeh
  • 18,498
emgh3i
  • 1,291
  • 1
  • 8
  • 2
19

This worked for me.

1) Login to your gmail account.

2) Go to https://www.google.com/settings/security/lesssecureapps and Turn On this feature.

3) Go to https://accounts.google.com/DisplayUnlockCaptcha and click Continue.

Then you can authenticate your Additional Email Address from your Gmail Account.

Edit: In my case it helped to write smtp.gmail.com instead of smtp.gmail.com:587.

neumde
  • 3
5

To fix this issue, you need to:

1) Login to your Gmail account using the web browser.

2) Click on this link to enable applications to access your account: https://accounts.google.com/b/0/DisplayUnlockCaptcha

3) Click on Continue button to complete the step.

4) Now try again to send the email from your PHP script. It should work.

4

I had this same issue, be sure to take a look at your gmail account security settings and enable "Access for less secure apps" from www.google.com/settings/security.

it will then magically start to work.

alan
  • 41
2

This happens because Google recently implemented a policy change, which in their own words, is one in a series of changes to strengthen email authentication, and end any practices by Google products which break authentication.

There are many options being suggested such as to change the ports for the smtp server, to enable "allow less secure apps" option in Security settings tab etc.

One solution which works, is to enable Gmail's Two step authentication for the AuthUser, generate an app specific password, and use this password as the Gmail password when setting up "Send mail as" option. Once you create an app only password and use it in /etc/ssmtp/ssmtp.conf, at AuthPass=, you can disable two step verification without revoking Two step verification.

mzhaase
  • 3,888
1

I fixed it by creating a new GMail account, for mail sending only, activated the two-phases-auth, and generated an app password.

It works like a charm!

0

Have you followed the provided link and read the instructions? This is how to fix it.

I'll bet you entered the wrong username or password.

If they are really correct, verify that you use the same port. Above you specified 587 whereas below you specified 25.

Then it is probably not OK to specify UseTLS and UseSTARTTLS. On port 587 use UseTLS, with port 25 use UseSTARTTLS.

At the end your hostname is likeley not "mailserver". Use a FQDN.

mailq
  • 17,251