(Gmail) not sending transactional emails

I keep getting Authentication required and I can’t spot where I am making the mistake.
Error sending email! Error sending email: Failed to send email. Reason: Authentication required, invalid details provided. Please check your email settings and resend the invitation.

And

  • How was Ghost installed and configured?
    Digital Ocean, Following the official docs How to install & setup Ghost on Ubuntu 16.04, 18.04, 20.04 or 22.04

  • What Node version, database, OS & browser are you using?
    OS: Ubuntu, v20.04.2 LTS
    Node Version: v14.17.4
    mysql Ver 8.0.26-0ubuntu0.20.04.2

  • What errors or information do you see in the console?
    Error: Authentication required, invalid details provided
    at SMTPTransport.sendMail (/var/www/writeit/versions/4.11.0/node_modules/nodemailer/lib/engines/smtp.js:124:22)

  • What steps could someone else take to reproduce the issue you’re having?
    I can’t spot the issue. I came across a recent post with someone having a similar issue, but isn’t getting any errors, but he uses Mailgun. I did open the firewall for that port after reading the post.

      "database": "writeit_prod"
    }
  },
  "mail": {
    "from": "email@gmail.com",
    "transport": "SMTP",
    "options": {
      "service": "gmail",
      "host": "smtp.gmail.com",
      "port": 587,
      "secureConnection": true,
      "auth": {
        "user": "email@gmail.com",
        "password": "xxxx xxxx xxxx xxxx" \\ Password**
      }
    }
  },
  "logging": {

** is the password generated by Gmail app supposed to contain spaces?
I’ve tried so many combinations with the config that my mind is spinning.

The only thing that I can think of is the issue is at Digital Ocean’s side. Are they blocking the port 587?
Or is there something else I am missing?

Edit: Tried port 465, allowed in firewall, same issue.

1 Like

Gmail has a few hurdles in place to prevent it being used as a general SMTP server which I expect are what you’re running into.

Is this a personal gmail account or are you using the Google Workspace SMTP relay service?

If it’s a personal gmail account then Gmail requires 2-step verification with oauth which isn’t a supported authentication process. In the past it was possible to turn on a “less secure apps” option but it looks like Google has removed that. You might be able to create an “App Password” but I’m not sure if that works without the less secure apps option.

"secureConnection": true, - this should be false for best compatibility. When it’s false an initial non-ssl connection will be made then TLS is used to negotiate a compatible encryption scheme before continuing.

If it’s possible for you I’d suggest switching to a dedicated transactional email service rather than trying to use a personal email account. Mailgun is our suggested option, you get 1250 emails a month for free and if you ever want to send newsletters from Ghost you’ll already be set up ready with an account.

3 Likes

Thank you for the detailed reply Kevin.

After a good night’s rest, I read your message, tested your suggestions without any luck and then dug a little deeper.

I am using a personal gmail account and I had set it up with 2-step verification. However, it is possible to “Allow less secure apps”, which google tries hard to dissuade people from doing - but they allow it. I created a new gmail account today, set “Allow less secure apps” to “ON”, copied a python script to send an email from the Digital Ocean Ubuntu server. The same one where Ghost is installed.

I received the email using the script on the same server. So the issue isn’t Digital Ocean nor Gmail.

I tried the new credentials in the config.production.json file, same issue. However, I am not sure if I am configuring it correctly.

  },
  "mail": {
    "from": "email@gmail.com",
    "transport": "SMTP",
    "options": {
      "service": "Gmail",
      "host": "smtp.gmail.com",
      "port": 465,
      "secure": true,
      "auth": {
        "user": "email@gmail.com",
        "password": "password"
      }
    }
  },

This is the script I used

import smtplib, ssl

class Mail:

    def __init__(self):
        self.port = 465
        self.smtp_server_domain_name = "smtp.gmail.com"
        self.sender_mail = "GMAIL_ADDRESS"
        self.password = "SECURE_PASSWORD"

    def send(self, emails, subject, content):
        ssl_context = ssl.create_default_context()
        service = smtplib.SMTP_SSL(self.smtp_server_domain_name, self.port, context=ssl_context)
        service.login(self.sender_mail, self.password)
        
        for email in emails:
            result = service.sendmail(self.sender_mail, email, f"Subject: {subject}\n{content}")

        service.quit()


if __name__ == '__main__':
    mails = input("Enter emails: ").split()
    subject = input("Enter subject: ")
    content = input("Enter content: ")

    mail = Mail()
    mail.send(mails, subject, content)

Sources:

1 Like

That’s not needed, the service config is used to set up host/port/etc but that is being provided manually. This shouldn’t affect anything because the manual config will override but it’s worth testing without it.

Can you try "secure": false? There are definitely known issues with "secure": true and the version of nodemailer that Ghost uses under the hood.

With "secure": false this will need to be port 587 so that TLS/STARTTLS can be used rather than initiating a secure connection immediately.

If none of those work, are there any other differences in the config between your Ghost setup and the python script setup? Are you using the same From address?

1 Like

First of all, I appreciate the help.

You know, I installed ghost last year on a server and the process went well. I hooked it up to a gmail account without any issues. Then came the ghost update, the upgrade got botched somehow and I simply deleted the server. Now that I’m trying to get it working again, I can not figure it out. And one thing that bugs me endlessly is not being able to figure something out.

I tried multiple combinations, but none of them worked. Nearing the end of the little hamster running around I decided to keep the gmail config but adding "service": "Mailgun", because why not?

I searched the web for a substantial amount of time, and apparently my search foo isn’t up to standards yet. And I am out of ideas. We know that gmail should work. The question is why isn’t it working?

Edit: It seems there is a limit to the message length… It cut out 2/3rd’s of the snippet below.

"service": "Gmail", (deleted)
"secure": false,  
"port": 587,
    
Error sending email! Error sending email: Failed to send email. Reason: Invalid login - 535-5.7.8 Username and Password not accepted. Learn more at 535 5.7.8 https://support.google.com/mail/?p=BadCredentials b17sm3825528pgl.61 - gsmtp. Please check your email settings and resend the invitation.

"service": "Gmail", (deleted)
"secure": true,  
"port": 587,

Error sending email! Error sending email: Failed to send email. Reason: Invalid login - 535-5.7.8 Username and Password not accepted. Learn more at 535 5.7.8 https://support.google.com/mail/?p=BadCredentials n23sm3775369pgv.76 - gsmtp. Please check your email settings and resend the invitation. 


"service": "Gmail", (deleted)
"secure": false,  
"port": 465, 
    
Error sending email! Error sending email: Failed to send email. Reason: Greeting never received. Please check your email settings and resend the invitation.


"service": "Gmail", (deleted)
"secure": true,  
"port": 465, 

Error sending email! Error sending email: Failed to send email. Reason: Greeting never received. Please check your email settings and resend the invitation.


CHANGED TO DEFAULT THEME

"service": "Gmail", (deleted)
"secureConnection": true,  
"port": 465, 

Error sending email! Error sending email: Failed to send email. Reason: Invalid login - 535-5.7.8 Username and Password not accepted. Learn more at 535 5.7.8 https://support.google.com/mail/?p=BadCredentials l12sm3467421pff.182 - gsmtp. Please check your email settings and resend the invitation.

"service": "Gmail", (deleted)
"secureConnection": false,  
"port": 465, 

Error sending email! Error sending email: Failed to send email. Reason: Greeting never received. Please check your email settings and resend the invitation.


"service": "Gmail", (deleted)
"secureConnection": false,  
"port": 587,

Error sending email! Error sending email: Failed to send email. Reason: Invalid login - 535-5.7.8 Username and Password not accepted. Learn more at 535 5.7.8 https://support.google.com/mail/?p=BadCredentials fz10sm3077340pjb.40 - gsmtp. Please check your email settings and resend the invitation.

"service": "Gmail", (deleted)
"secureConnection": true,  
"port": 587,

Error sending email! Error sending email: Failed to send email. Reason: 139807638235008:error:1408F10B:SSL routines:ssl3_get_record:wrong version number:../deps/openssl/openssl/ssl/record/ssl3_record.c:332: . Please check your email settings and resend the invitation.


"service": "Gmail", (deleted)
"secureConnection": true,  
"port": 587,
"user": "username"  //removed @gmail

Error sending email! Error sending email: Failed to send email. Reason: 140104037279616:error:1408F10B:SSL routines:ssl3_get_record:wrong version number:../deps/openssl/openssl/ssl/record/ssl3_record.c:332: . Please check your email settings and resend the invitation.


"service": "Gmail", (deleted)
"secureConnection": true,  
"port": 465,
"user": "username"  //removed @gmail

Error sending email! Error sending email: Failed to send email. Reason: Invalid login - 535-5.7.8 Username and Password not accepted. Learn more at 535 5.7.8 https://support.google.com/mail/?p=BadCredentials y7sm6964069pjb.52 - gsmtp. Please check your email settings and resend the invitation.


"service": "Gmail", (deleted)
"secureConnection": false,  
"port": 465,
"user": "username"  //removed @gmail

Error sending email! Error sending email: Failed to send email. Reason: Greeting never received. Please check your email settings and resend the invitation.


"service": "Gmail", (deleted)
"secure": false,  
"port": 465,
"user": "username"  //removed @gmail

Error sending email! Error sending email: Failed to send email. Reason: Greeting never received. Please check your email settings and resend the invitation.

"service": "Gmail", (deleted)
"secure": true,  
"port": 465,
"user": "username"  //removed @gmail

Error sending email! Error sending email: Failed to send email. Reason: Greeting never received. Please check your email settings and resend the invitation.
1 Like

I created an account with a different provider, same issue.

Came here to see if this would, somehow, help me fix a similar issue (using Mailersend). Curious: Did you figure something out?