Configure Your Ghost to SMTP through sendmail/Postfix (when all else fails)
July 1, 2019

Configure Your Ghost to SMTP through sendmail/Postfix (when all else fails)

If you are using one of the "recommended" email providers such as Mailgun you should be fine following the official setup guide. Unfortunately, if you are hosting your email elsewhere (or, God forbid, running your own MTA), then Ghost can quickly let you down. For me, I have my mail hosted at Lunarpages - and Ghost refused to play nice despite all my efforts. Ghost uses Nodemailer for sending email. I think one of the main problems is that it's using an ancient version of Nodemailer (v0.7, when the current package is past v6). There is an issue on github on updating Nodemailer but nobody seems to care much. Makes one wonder if Ghost truly is dead. I hope not, because it is a good tool for what it does.

Gmail Config

The following worked for me when sending through gmail:

  "mail": {
    "from": "",
    "transport": "SMTP",
    "options": {
      "host": "",
      "port": 465,
      "secureConnection": true,
      "auth": {
        "user": "",
        "pass": "PASSWORD"

You will have to "allow less secure apps" for the above to work.

BUT this post is not about sending Ghost email through Gmail, but about sending it through a "regular" smtp server hosted for you at your ISP!

Quick Reference of Commands Used

# Edit email credentials, "cook" the file, postfix configuration, restart: 
$ sudo vi /etc/postfix/sasl_passwd
$ sudo postmap /etc/postfix/sasl_passwd
$ sudo vi /etc/postfix/
$ sudo service postfix restart
# Send a test email:
$ echo "This is a test email body." | mail -s "Subject" RECIPIENT@EMAIL.ADDRESS
# Restart postfix


Server: Ubuntu 18.10
Ghost: self-hosted, 2.25.2


My specific setup is super simple. My host allows SMTP either with or without authentication. But however I configured Ghost, I would just run into this error:

Greeting never received

I tried various combinations for my config.production.json. I'll share it with you because some of this might work for you:

  mail: {
    transport: 'SMTP',
    options: {
      "host": "mail.???.com",
      "secure": false,
      "secureConnection": false, <!-- see
      "port": 587,	<-- this is the NON-SSL port for me, but I also tried 465 
                        with "secure": true
      "ignoreTLS": true,	<-- force nodemailer not to use tls
      "auth": {
        "user": "???@???",
        "pass": "???"
      "tls": {
        "rejectUnauthorized": false
      "debug": true, <-- supposedly instructs nodemailer to write 
                         error messages to stdout
      "log": true	<-- supposedly adds logging to nodemailer, 
                        but couldn't find the actual logs

I tried watching the ghost log while using the email test button to see if there is any more info there:

tail content/logs/???_production.log

But the logs were of no help:

..."code":"ETIMEDOUT","name":"EmailError","statusCode":500,"level":"normal","message":"Failed to send email. Reason: Greeting never received.","help":"\"Please see for instructions on configuring email.\"","stack":"EmailError: Failed to send email. Reason: Greeting never received.\n    at EmailError.GhostError (/var/www/???.com/en/versions/2.25.2/core/server/lib/common/errors.js:10:26)\n    at new EmailError (/var/www/???.com/en/versions/2.25.2/core/server/lib/common/errors.js:34:20)\n    at MailComposer.returnCallback (/var/www/???.com/en/versions/2.25.2/core/server/services/mail/GhostMailer.js:77:31)\n    at SMTPConnectionPool._onConnectionError (/var/www/???.com/en/versions/2.25.2/node_modules/simplesmtp/lib/pool.js:334:17)\n    at SMTPClient.emit (events.js:198:13)\n    at SMTPClient.EventEmitter.emit (domain.js:448:20)\n    at SMTPClient.<anonymous> (/var/www/???.com/en/versions/2.25.2/node_modules/simplesmtp/lib/client.js:293:18)\n    at ontimeout (timers.js:436:11)\n    at tryOnTimeout (timers.js:300:5)\n    at listOnTimeout (timers.js:263:5)\n    at Timer.processTimers (timers.js:223:10)\n\nError: Greeting never received\n    at SMTPClient.<anonymous> (/var/www/???.com/en/versions/2.25.2/node_modules/simplesmtp/lib/client.js:289:25)\n    at ontimeout (timers.js:436:11)\n    at tryOnTimeout (timers.js:300:5)\n    at listOnTimeout (timers.js:263:5)\n    at Timer.processTimers (timers.js:223:10)"},"msg":"Failed to send email. Reason: Greeting never received.","time":"2019-07-01T08:19:20.343Z","v":0}

After wasting way too much time trying to go the Ghost route, I decided to use a solid, Linux community supported mailer. After considering sendmail, as well as simpler alternatives such as ssmtp and msmtp and opensmtpd I ended up choosing postfix because it is widely used and has a lot of configuration options.

Towards a Solution

First, make sure sendmail exists on your platform: which sendmail

This should return something similar to  /usr/sbin/sendmail

Set your FQDN

hostnamectl set-hostname new-hostname

vi /etc/hosts

Make sure local port 25 is open

For postfix to work, it needs to be able to receive incoming connections from localhost. Ensure that port 25 is open:

sudo apt install net-tools

netstat -tulpn | grep :25

Install Postfix

Install postfix and utilities, such as "mail":
$ sudo apt-get install mailutils
...alternatively, install postfix only:
$ sudo apt-get install postfix

On the second screen, set the actual FQDN of your server. This is not the same as hostname of the 3rd party SMTP server that you use.

You can reconfigure postfix at any time with sudo dpkg-reconfigure postfix

Set your Username/Password

This is a rundown of a detailed explanation:

$ sudo vi /etc/postfix/sasl_passwd
   Set the file to:
YOUR.ISP.SERVER:587 username:password
$ sudo vi /etc/postfix/
   Make sure you have: 
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
$ sudo chown root:root /etc/postfix/sasl_passwd /etc/postfix/sasl_passwd.db
x$ sudo chmod 0600 /etc/postfix/sasl_passwd /etc/postfix/sasl_passwd.db
$ sudo postmap /etc/postfix/sasl_passwd
$ sudo service postfix reload

Configure Postfix

sudo vi /etc/postfix/

There are a plethora of options, you will probably need the following:

smtpd_banner = $myhostname ESMTP $mail_name (Ubuntu)
biff = no

# appending .domain is the MUA's job.
append_dot_mydomain = no

# Uncomment the next line to generate "delayed mail" warnings
#delay_warning_time = 4h

readme_directory = no

# See -- default to 2 on
# fresh installs.
compatibility_level = 2

# TLS parameters
smtpd_tls_session_cache_database = btree:${data_directory}/smtpd_scache
smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache

# See /usr/share/doc/postfix/TLS_README.gz in the postfix-doc package for
# information on enabling SSL in the smtp client.

smtpd_relay_restrictions = permit_mynetworks permit_sasl_authenticated defer_unauth_destination
myhostname =
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
myorigin = /etc/mailname
mydestination = zen2, localhost.localdomain, localhost
mynetworks = [::ffff:]/104 [::1]/128
mailbox_command = procmail -a "$EXTENSION"
mailbox_size_limit = 0
recipient_delimiter = +
inet_protocols = all

# Enable auth
smtp_sasl_auth_enable = yes
smtp_tls_wrappermode = yes
# Set username and password
# A less secure method would be: smtp_sasl_password_maps =
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_security_options = noanonymous
# Turn on tls encryption
smtp_use_tls = yes
smtp_tls_security_level = encrypt
header_size_limit = 4096000
# Set external SMTP relay host here IP or hostname accepted along with a port number.
relayhost =
# accept email from our web-server only
inet_interfaces = localhost

sender_canonical_classes = envelope_sender, header_sender
sender_canonical_maps =  regexp:/etc/postfix/sender_canonical_maps
smtp_header_checks = regexp:/etc/postfix/header_check

A non-encrypted option would look like the above except:

#smtp_tls_wrappermode = yes
smtp_use_tls = no
#smtp_tls_security_level = encrypt

After updating run service postfix restart

Forward System Mail

If you want to forward all mail sent to root, then sudo vi /etc/aliases

# See man 5 aliases for format
postmaster:    root

And then run sudo newaliases

Force the FROM Address

When testing postfix with echo "This is a test email body." | mail -s "Subject" RECIPIENT_EMAIL@SERVER.COM, the server will set the from address automatically to the user you are logged in as. Additionally, if any local app tries to send mail with sendmail, if it doesn't explicitly specify a from address then again the above will happen.

I have a dedicated email address for each of my servers, so to make things easy, I force the FROM address to always be that dedicated email address. There is a detailed answer to this on stackoverflow. Here's a quick rundown:

$ sudo vi /etc/postfix/
...add the following to the end:
sender_canonical_classes = envelope_sender, header_sender
sender_canonical_maps =  regexp:/etc/postfix/sender_canonical_maps
smtp_header_checks = regexp:/etc/postfix/header_check
$ sudo vi /etc/postfix/sender_canonical_maps
$ sudo vi /etc/postfix/header_check
/From:.*/ REPLACE From:

Allow Postfix through your Firewall

You would only need to take this step if you are using postfix to receive email!

sudo ufw allow postfix

Alternatively, you can allow only specific ports: sudo ufw allow 587

Test Postfix

echo "This is a test email body." | mail -s "Subject" -a "From: YOUR_EMAIL@SERVER.COM" RECIPIENT_EMAIL@SERVER.COM

Or, to send from the default address:

echo "This is a test email body." | mail -s "Subject" RECIPIENT_EMAIL@SERVER.COM

To watch for any errors, run this on a separater terminal while running the above:

sudo tail -f /var/log/mail.log
sudo tail -f /var/log/mail.err

Issues? Kill sendmail-mta

If you see something like this while starting postfix sudo systemctl start postfix and tailing mail.log sudo tail -f /var/log/mail.log:

fatal: bind port 25: Address already in use

Then try sudo killall sendmail, if you see:

sendmail: no process found

Then you may need to sudo killall sendmail-mta

Explicitly tell ghost to use sendmail

To do so, set your ghost config email section to the following:

  mail: {
    "from": "Ghost <ghost@???.com>",
    "transport": "SMTP",
    "options": {
      "service": "sendmail",

Don't forget to service ghost restart


General Ghost Email Config Tutorials

PostFix + Ghost

Configure Your Ghost to SMTP through sendmail/Postfix (when all else fails)
Share this