69

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
  • 37,618
  • 10
  • 90
  • 145
Connect
  • 801
  • 1
  • 7
  • 4
  • possible duplicate of [sSMTP Unable to send message using external mail server SMTP](http://serverfault.com/questions/405567/ssmtp-unable-to-send-message-using-external-mail-server-smtp) – mailq Oct 10 '14 at 17:50
  • Got this error last night after it has been working for several months. – ceving Sep 30 '15 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 – Scott Stensland Aug 29 '16 at 21:48
  • @ceving what was the remedy? How did you fix it? – 3kstc Dec 07 '17 at 03:03

7 Answers7

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.

masegaloeh
  • 17,978
  • 9
  • 56
  • 104
emgh3i
  • 1,281
  • 1
  • 8
  • 2
  • 10
    Option 1. worked for me – Patrick Forget Sep 30 '15 at 18:40
  • 1
    FYI, you can enable this for your entire company if using google apps for business, in Security settings. – Travis Reeder Apr 09 '16 at 20:44
  • 9
    +1, Option 1 followed by https://g.co/allowaccess worked perfectly. – greg_data Jan 03 '17 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 '17 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 https://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 '21 at 23:12
  • https://g.co/allowaccess saved my day! – Billy Chen Apr 08 '21 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.

neumde
  • 3
  • 2
user329161
  • 191
  • 1
  • 2
  • I have the same problem, I followed your steps, 1), 2) and 3), still get: "sSMTP[17921]: Authorization failed (535 5.7.8 https://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 '20 at 17:43
  • 2
    #3 was the missing part for me! – aardvarkk Aug 16 '20 at 06: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.

Kamal Kumar
  • 181
  • 1
  • 4
  • 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](https://support.google.com/accounts/answer/6010255?hl=en). – Reaces Jan 09 '15 at 10:49
  • It worked for me. Linux core install. I logged from another computer. – Michal Sokolowski May 28 '15 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.

alan
  • 41
  • 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](http://askubuntu.com/questions/12917/how-to-send-mail-from-the-command-line) –  Jan 01 '15 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.

mzhaase
  • 3,778
  • 2
  • 19
  • 32
Joel G Mathew
  • 890
  • 1
  • 9
  • 18
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
  • 16,882
  • 2
  • 36
  • 66