How to setup basic SMTP for Ghost

How to setup basic SMTP for Ghost

Almost everybody has Gmail, right? But a small amount of those knows, that it also includes free SMTP service, which is the same as other Google products: fast&reliable.

Everything you need is your email and dedicated app password (for security reasons).

:old_key: To generate this password :

  1. Go to https://myaccount.google.com/apppasswords
  2. Enter your regular password from your Google account (this is security settings)
  3. Select app, choose Other, and put the name (i.e SMTP)
  4. Now copy your password and write it down (you will have no chance to see it for the second time here)

For Ghost setup, I was using DO droplet, you could use a different way, but the whole flow should be similar or the same.

:e-mail: Now, to setup SMTP for your Ghost:

  1. Go to your project directory cd /var/www/ghost
  2. Open to edit your config.production.json
  3. Copy and paste config object for mail and fill user and pass with your creds
"mail": {
    "transport": "SMTP",
    "options": {
      "service": "Google",
      "host": "smtp.gmail.com",
      "port": 587,
      "auth": {
        "user": "your@google.email",
        "pass": "this password"
      }
    }
  },

You could burn down the paper with this password .

As a result, all your transactional emails should work fine without any additional pain in the ass. For example, now you could invite somebody else as a content contributor to your website.

Originally published on How to setup basic SMTP for Ghost - DEV Community

3 Likes

For anyone who gets hung up on making an app password, Google only offers this option if you have 2FA turned on. So thatā€™s your first step! :slight_smile:

Hope that helps someone else!

This works great for transactional emails on my Windows-running development setup.

2 Likes

However, if appears that Ghost only supports non-2FA gmail - so it is not possible to use a personal non-2FA gmail account for Ghost - correct? What are the Google alternatives for using their SMTP server?

Welcome to Ghost, @Michael_Lavelle !

I have 2FA on my personal Gmail, and Iā€™m using that to send Ghost transactional emails on a couple of dev setups. (For production, I use mailgun for transactional email or else my own SMTP server.)

You can turn 2FA on pretty easily for a Gmail account. I donā€™t think it costs anything or needs special account access. Ghost doesnā€™t actually USE 2FA when it connects to Googleā€™s SMTP server - it uses the app password, itā€™s just that you need to have app passwords available, which requires 2FA.

Iā€™ve got a few more details about that setup here: How to deliver Ghost emails from your local dev setup

You certainly donā€™t have to use Gmail. You could instead configure an outgoing mail server and tell Ghost to use it, or you could set up a mailgun account (needed for newsletters anyway) and tell Ghost to use that. There are options described here:

I think at this point Iā€™ve done all the options listed for transactional email except SES. None of them are terrible to set up, but if you really donā€™t want to do server setup or any sort, you might also want to give Ghost Pro another look, since they make all that stuff ā€˜just workā€™.

Thank you for this fast response. Turns out the ā€œserviceā€ line was preventing Ghost from starting properly - deleting it solved that problem. Looks like email is working now. Interestingly I found several references that included the ā€œserviceā€ line and several that did not. It might be that mailgun requires the ā€œserviceā€ line. In any case thank you so much. Mike

2 Likes

Iā€™m glad that you were able to get it working, and thanks for coming back to document the fix!!

@chakzefir Do you know how to set it up so that it uses an preconfigured alias?

Iā€™ve setup an alias on my gmail that is noreply@mywebsite.com, and I want to use that instead of my own gmail address.

Iā€™ve tried using that alias as options.auth.user, and as options.from, but the mails that it sends still show my original gmail address.

Hey bazoo,

I think you rather need to create dedicated email address and setup the same for noreply@mywebsite.com

Thatā€™s weird, but I canā€™t figure out the config for production with any of options listed: Gmail SMTP, Amazon SES, tested with Ethereal email as well, but nothing works. I canā€™t invite another editor / website admin because of this. Tested with 587 port as well as 465. Tested with quotes and without, with line ā€œserviceā€ and without. Maybe thereā€™s an issue with Nodemailer on the server? We used docker image on AWS EC2, ssh access. Configured as per Ghost documentation with the separate user and permissions.

What error messages do you have? (Start with wherever ghost is logging - probably ghost-directory/content/logs .)

Hey, the error and info logs are empty or have older messages which are irrelevant (by timestamps). Only old 403 no permission http requests on update from another day. I guess that if there would be a problem between Ghost server and Nodemailer, it would show there. I have an assumption it might be due to restrictive VPC/VPN configuration that our devop guy setup. The EC2 server only open through 22 port and 443 and 80 are thrown through the network gateway so that the load balancer keeps control over the traffic. Can this be a problem? Any other ports have to be seen through outside to make transactional emails to happen? Website is reachable by opening in a web browser.

I also wonder why your config for Gmail SMTP does not work. Tried removing the ā€œserviceā€ line as Michael_Lavelle suggested, but no luck. 2FA turned on, got the App Password the right way, it shows a 16-[a] password with spaces between 4-letter blocks, tested both with spaces and without. ā”(ļæ£ćƒ®ļæ£)ā”Œ

I donā€™t know enough about your setup to tell you where to look for logs.

If you visit your site, do you see the visit logged in info? If not, you might have the wrong logsā€¦

You could very well have necessary ports blocked. If you want more help, post mail config details from cobfig.production.json and details about your server setup.

Could also be a proxying bug. Check the browser console for logs also. (F12)

Oh, thanks for the tip! Indeed, I see the initiated POST request with a new stuff member email data to the /ghost/api/admin/invites/ endpoint. It fails with 504 error code gateway timeout. :thinking:ā€¦

I think odds are that it isnā€™t reaching the server. Do you see it in your
logs? Check your proxy setup if not,