December 17, 2017

Configuring a Google Cloud Ghost Deployment to Use Mailgun

Google Compute Engine does not allow outbound connections from instances on ports 25, 465, and 587. They say it is because too many people abused instances for sending spam. Judging by my inbox unread count, I'd say it's about time. ;)

311183545_4ace03b7d0-1

These port blocks apply to instances running containers, such as those used to run this blog on Kubernetes (GKE). After hunting around a bit for a solution to enable Ghost to send mail, I figured out that port 2525 can be used for outbound SMTP connections for Mailgun, which are not blocked by Google.

sending

Here's my resulting config.production.json file, which is being used on this site:

{
  "url": "http://stackgeek.com",
  "server": {
    "port": 2368,
    "host": "0.0.0.0"
  },
  "database": {
    "client": "sqlite3",
    "connection": {
      "filename": "/var/lib/ghost/content/data/ghost.db"
    }
  },
  "logging": {
    "transports": [
      "file",
      "stdout"
    ]
  },
  "process": "systemd",
  "paths": {
    "contentPath": "/var/lib/ghost/content"
  },
  "mail": {
    "transport": "SMTP",
    "options": {
        "host": "smtp.mailgun.org",
        "port": 2525,
        "service": "Mailgun",
        "auth": {
          "user": "postmaster@mg.stackgeek.com",
          "pass": "xxxxx"
        }
    }
  },
  "admin": {
    "url": "https://stackgeek.com"
  }
}

Note the explicit use of a host entry and port number in the configuration file, given the need to call a different port.

More information about setting up and configuring Ghost, including configuring password secrets with GCP, will be available in the Installing Ghost on Kubernetes Guide soon!