71

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 = [email protected]
# 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

[email protected]
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:[email protected]:mailhub.your.domain[:port]

root:[email protected]: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

4
  • possible duplicate of sSMTP Unable to send message using external mail server SMTP
    – mailq
    Oct 10, 2014 at 17:50
  • Got this error last night after it has been working for several months.
    – ceving
    Sep 30, 2015 at 18:15
  • After doing all the suggested steps it still failed UNTIL I simply changed my gmail.com password even though I was using correct password ... maybe its a new Google security precaution Aug 29, 2016 at 21:48
  • @ceving what was the remedy? How did you fix it?
    – 3kstc
    Dec 7, 2017 at 3:03

7 Answers 7

118

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.

6
  • 10
    Option 1. worked for me Sep 30, 2015 at 18:40
  • 1
    FYI, you can enable this for your entire company if using google apps for business, in Security settings. Apr 9, 2016 at 20:44
  • 9
    +1, Option 1 followed by g.co/allowaccess worked perfectly.
    – greg_data
    Jan 3, 2017 at 12:06
  • Took me a few minutes but I found how to enable for entire organization in Admin Console under Security > Basic Settings > Less Secure Apps > Enforce Access ... which for the sake of added confusion shows "Advanced security settings" in the title (though I couldn't find a link to that page via the Advanced security settings...). Confused? So am I!
    – isapir
    Jan 24, 2017 at 17:30
  • 1
    +1 to Option 2 with specifically this fix: "Still having trouble signing in? If you still can’t sign in to your account on the app, try the following: On your device’s browser, go to accounts.google.com/DisplayUnlockCaptcha. Enter your username and password, then enter the letters on the screen. Go back to the app and try signing in again."
    – Bradley
    Feb 25, 2021 at 23:12
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.

2
  • I have the same problem, I followed your steps, 1), 2) and 3), still get: "sSMTP[17921]: Authorization failed (535 5.7.8 support.google.com/mail/?p=BadCredentials s71sm11591505qke.0 - gsmtp" Why do you mean by "Then you can authenticate your Additional Email Address from your Gmail Account."?
    – Erwann
    Jun 27, 2020 at 17:43
  • 2
    #3 was the missing part for me!
    – aardvarkk
    Aug 16, 2020 at 6:42
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.

2
  • This might not really be an answer for a linux core install. And I'm not entirely sure this will persist after daemon restarts. You're better off following the insecure app instructions.
    – Reaces
    Jan 9, 2015 at 10:49
  • It worked for me. Linux core install. I logged from another computer. May 28, 2015 at 13:53
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.

1
  • This is helpful and i fixed the same problem after applying change to my gmail account security settings by allowing "Access for less secure apps" from www.google.com/settings/security. The related helpful link can be found here
    – user261995
    Jan 1, 2015 at 13:42
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.

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.

3
  • @mmailq,As per your solution I changed the port no to 587 on both the conf file and I am sure that the username and password are correct.
    – Connect
    Oct 10, 2014 at 17:43
  • @@mmailq,what should be the FQDN? my server hostname is mailserver.
    – Connect
    Oct 10, 2014 at 17:45
  • @@mmailq, no it is not working the same error is coming.
    – Connect
    Oct 10, 2014 at 17:52

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .