# How to add SMTP (mail) configuration?

**URL:** <https://forum.ghost.org/t/how-to-add-smtp-mail-configuration/40981>\
**Category:** Self-hosting\
**Created:** [September 4, 2023, 8:30pm UTC](https://forum.ghost.org/t/how-to-add-smtp-mail-configuration/40981 "2023-09-04T20:30:33Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![SchBenedikt](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.ghost.org/schbenedikt/32/26193_2.png) [@SchBenedikt](https://forum.ghost.org/u/SchBenedikt)\
**Post date:** [September 4, 2023, 8:30pm UTC](https://forum.ghost.org/t/how-to-add-smtp-mail-configuration/40981/1 "2023-09-04T20:30:33Z")

</div>

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

```auto
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.

---

<div class="post-metadata">

**Author:** ![hostingpeep](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.ghost.org/hostingpeep/32/20842_2.png) [@hostingpeep](https://forum.ghost.org/u/hostingpeep)\
**Post date:** [September 5, 2023, 3:23am UTC](https://forum.ghost.org/t/how-to-add-smtp-mail-configuration/40981/2 "2023-09-05T03:23:20Z")

</div>

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

```auto
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](https://forum.ghost.org/t/how-to-setup-basic-smtp-for-ghost/29166)

---

<div class="post-metadata">

**Author:** ![SchBenedikt](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.ghost.org/schbenedikt/32/26193_2.png) [@SchBenedikt](https://forum.ghost.org/u/SchBenedikt)\
**Post date:** [September 5, 2023, 7:27am UTC](https://forum.ghost.org/t/how-to-add-smtp-mail-configuration/40981/3 "2023-09-05T07:27:50Z")

</div>

@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!

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

```

---

<div class="post-metadata">

**Author:** ![hostingpeep](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.ghost.org/hostingpeep/32/20842_2.png) [@hostingpeep](https://forum.ghost.org/u/hostingpeep)\
**Post date:** [September 5, 2023, 7:44am UTC](https://forum.ghost.org/t/how-to-add-smtp-mail-configuration/40981/4 "2023-09-05T07:44:36Z")

</div>

> <https://github.com/clean-docker/ghost-cms/blob/master/config.production.json>

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

---

<div class="post-metadata">

**Author:** ![SchBenedikt](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.ghost.org/schbenedikt/32/26193_2.png) [@SchBenedikt](https://forum.ghost.org/u/SchBenedikt)\
**Post date:** [September 5, 2023, 1:34pm UTC](https://forum.ghost.org/t/how-to-add-smtp-mail-configuration/40981/6 "2023-09-05T13:34:43Z")

</div>

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

```auto
{
  "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

```auto
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

```

---

<div class="post-metadata">

**Author:** ![Kevin](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.ghost.org/kevin/32/32_2.png) [@Kevin](https://forum.ghost.org/u/Kevin)\
**Post date:** [September 5, 2023, 1:58pm UTC](https://forum.ghost.org/t/how-to-add-smtp-mail-configuration/40981/7 "2023-09-05T13:58:06Z")

</div>

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.

```auto
    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](https://ghost.org/docs/config/)

---

<div class="post-metadata">

**Author:** ![SchBenedikt](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.ghost.org/schbenedikt/32/26193_2.png) [@SchBenedikt](https://forum.ghost.org/u/SchBenedikt)\
**Post date:** [September 5, 2023, 2:14pm UTC](https://forum.ghost.org/t/how-to-add-smtp-mail-configuration/40981/8 "2023-09-05T14:14:02Z")

</div>

@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!

---

<div class="post-metadata">

**Author:** ![kasir-barati](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.ghost.org/kasir-barati/32/30121_2.png) [@kasir-barati](https://forum.ghost.org/u/kasir-barati)\
**Post date:** [April 26, 2024, 1:50pm UTC](https://forum.ghost.org/t/how-to-add-smtp-mail-configuration/40981/9 "2024-04-26T13:50:50Z")

</div>

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](https://github.com/kasir-barati/docker/tree/docker-compose/docker-compose-files/ghost)

Give it a star if you liked it and it was helpful 🙂.
