How to add SMTP (mail) configuration?

Hello,
I installed Ghost via a Docker installation and am now very satisfied. I used the following as Docker-Compose code:

version: '3.1'

services:

  ghost:
    image: ghost:4-alpine
    restart: always
    ports:
      - 8080:2368
    environment:
      # see https://ghost.org/docs/config/#configuration-options
      database__client: mysql
      database__connection__host: db
      database__connection__user: root
      database__connection__password: example
      database__connection__database: ghost
      # this url value is just an example, and is likely wrong for your environment!
      url: http://localhost:8080
      # contrary to the default mentioned in the linked documentation, this image defaults to NODE_ENV=production (so development mode needs to be explicitly specified if desired)
      #NODE_ENV: development

  db:
    image: mysql:8.0
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: example

I’ll have that with
docker-compose up -d
started.

My question is how do I now correctly add the SMTP configuration to this file.

Thank you,
schBenedikt.

You need to add volume for config file, where you will able to add smtp configuration.
Like this

volumes:
        - ./content:/var/lib/ghost/content
        - ./config.production.json:/var/lib/ghost/config.production.json

You can modify it accordingly.

Question is already asked here. How to setup basic SMTP for Ghost

@hostingpeep
Thanks for your answer - I added the code to my configuration file, but whenever I start the container I can no longer open the port (8089 in my case) - it is no longer displayed in Portainer either. Do you know what’s up?
Best regards!

--ghost
----config.production.json
----docker-compose.yml

Default configuration you can add to your file. Do changes accordingly.

@hostingpeep This is my configuration. But I can’t open the IP address - nothing happens there.
config-production.json

{
  "url": "http://IP-ADRESS:8780",
  "server": {
      "port": 8780,
      "host": "0.0.0.0"
    },
    "database": {
      "client": "mysql",
      "connection": {
          "host": "db",
          "user": "root",
          "password": "example",
          "database": "ghost",
          "charset": "utf8"
      }
    },
    "mail": {
      "from": "'MyDomain' <postmaster@mail.mydomain.com>",
      "transport": "SMTP",
      "options": {
        "service": "Mailgun",
        "host": "smtp.mailgun.org",
        "port": 465,
        "secureConnection": true,
        "auth": {
          "user": "postmaster@mail.mydomain.com",
          "pass": "7adsf7f8asd8f6as7asd7f-123sdf8-asdf87fa"
        }
      }
    },
  "logging": {
      "transports": [
            "file",
            "stdout"
          ]
    },
  "process": "systemd",
  "paths": {
      "contentPath": "/var/lib/ghost/content"
    }
}

docker-compose.yml

version: '3.1'

services:

  ghost:
    image: ghost:latest
    restart: always
    ports:
      - 8780:2368
    environment:
      # see https://ghost.org/docs/config/#configuration-options
      database__client: mysql
      database__connection__host: db
      database__connection__user: root
      database__connection__password: example
      database__connection__database: ghost
      # this url value is just an example, and is likely wrong for your environment!
      url: http://IP-ADRESS:8780
      # contrary to the default mentioned in the linked documentation, this image defaults to NODE_ENV=production (so development mode needs to be explicitly specified if desired)
      #NODE_ENV: development
    volumes:
      - ./content:/var/lib/ghost/content
      - ./config.production.json:/var/lib/ghost/config.production.json

  db:
    image: mysql:8.0
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: example

Everything that’s in the config file can be set via env vars and vice-versa. You should choose one method that suits how you want to set up your container rather than defining things twice and adding confusion over what is set where.

If you get rid of the config file you can keep your docker config and add the mail options, e.g.

    environment:
      # see https://ghost.org/docs/config/#configuration-options
      database__client: mysql
      database__connection__host: db
      database__connection__user: root
      database__connection__password: example
      database__connection__database: ghost
      # this url value is just an example, and is likely wrong for your environment!
      url: http://localhost:8080
      # contrary to the default mentioned in the linked documentation, this image defaults to NODE_ENV=production (so development mode needs to be explicitly specified if desired)
      #NODE_ENV: development
      mail__from: "'MyDomain' <postmaster@mail.mydomain.com>"
      mail__transport: "SMTP"
      mail__options__host: "smtp.mailgun.org"
      mail__options__port: 465
      ...

More info on config can be found in the documentation Configuration - Adapt your publication to suit your needs

1 Like

@Kevin
Thanks for the quick reply - I have now configured it this way (I added the email address and password to it)
And I can’t even tell you how grateful I am to you for this working answer!
But I have one more request:

It’s best to write exactly what you sent me somewhere in the config file - then it will be much easier for many people to do the right configuration.
Thanks!

1 Like

For those of you who wanted to experiment with Ghost on your local machine in Docker and need to configure a very simple SMTP in docker you can check my repo over here: docker/docker-compose-files/ghost at docker-compose · kasir-barati/docker · GitHub

Give it a star if you liked it and it was helpful :slightly_smiling_face:.