[Solved] SMTP issues on port 587 (docker compose, nginx)

Hello. I’ve checked out the other SMTP posts but none seem to address my issue(?) if it is an issue.

I’m using docker compose to deploy my Ghost instance. I set up Mailgun, all check marks are green on that side.

I’ve tried this with the Debian image on Ghost versions 5.94.2 and 5.96.1.

In the admin UI:

  • I set the Mailgun domain as: https://api.mailgun.net/v3/<mx.verified.domain>
  • I added the API key (not user password or sending key).

I’ve also tried removing my domain from the field but it didn’t seem to have any effect.

In docker-compose.yml, in the environment block for the ghost container, I have these options for mail:

mail__from: <user>@<mx.verified.domain>
mail__transport: SMTP
mail__options__service: Mailgun
mail__options__host: smtp.mailgun.org
mail__options__port: 587
mail__options__secure: false
mail__options__requireTLS: true
mail__options__auth__user: <user>@<mx.verified.domain>
mail__options__auth__pass: ${password}

Transactional mail is working as far as I can tell. I can sign up and login.

When I try to send bulk mail, I get

ghost-1  | 2024-10-13T03:17:40.651572966Z [2024-10-13 03:17:40] ERROR Method Not Allowed: Request failed with status code 405
ghost-1  | 2024-10-13T03:17:40.651585139Z
ghost-1  | 2024-10-13T03:17:40.651588326Z Method Not Allowed: Request failed with status code 405
ghost-1  | 2024-10-13T03:17:40.651591030Z
ghost-1  | 2024-10-13T03:17:40.651593175Z "Mailgun Error 405: Request failed with status code 405"
ghost-1  | 2024-10-13T03:17:40.651595549Z "https://ghost.org/docs/newsletters/#bulk-email-configuration"
ghost-1  | 2024-10-13T03:17:40.651610447Z
ghost-1  | 2024-10-13T03:17:40.651612471Z Error ID:
ghost-1  | 2024-10-13T03:17:40.651614765Z     b46f0a00-8911-11ef-ba88-11c62c81986f
ghost-1  | 2024-10-13T03:17:40.651616989Z
ghost-1  | 2024-10-13T03:17:40.651619103Z Error Code:
ghost-1  | 2024-10-13T03:17:40.651621287Z     BULK_EMAIL_SEND_FAILED
ghost-1  | 2024-10-13T03:17:40.651623472Z
ghost-1  | 2024-10-13T03:17:40.651625405Z Details:
ghost-1  | 2024-10-13T03:17:40.651638370Z     {"error":{"status":405,"message":"Method Not Allowed","details":"Request failed with status code 405","type":"MailgunAPIError"}

Despite this… Mailgun seems to report that mails have gone out. Everything has been delivered according to their chart. Ghost reports mails have gone out. Nothing arrives in any of my test inboxes. I’ve checked spam/junk, searched, etc.

I also see these errors I guess whenever analytics jobs run:

ghost-1  | 2024-10-13T03:30:43.093400343Z [2024-10-13 03:30:43] ERROR Method Not Allowed
ghost-1  | 2024-10-13T03:30:43.093798586Z [2024-10-13 03:30:43] ERROR [EmailAnalytics] Error while fetching
ghost-1  | 2024-10-13T03:30:43.094091088Z [2024-10-13 03:30:43] ERROR Method Not Allowed
ghost-1  | 2024-10-13T03:30:43.094275877Z [2024-10-13 03:30:43] INFO [EmailAnalytics] No new events found
ghost-1  | 2024-10-13T03:30:43.097692633Z [2024-10-13 03:30:43] ERROR Error while fetching email analytics Method Not Allowed
ghost-1  | 2024-10-13T03:30:43.098410710Z [2024-10-13 03:30:43] ERROR Method Not Allowed

What am I missing?

Just as a note, I’m using 587 because I wasn’t able to reach ports 25 or 465 from my VPS. I’m open to changing it to 465 for TLS by default if it’s misconfigured or this isn’t a “proper” way to check it on my end.

curl -v telnet://smtp.mailgun.org:25
* Host smtp.mailgun.org:25 was resolved.
* IPv6: (none)
* IPv4: 34.160.157.95
*   Trying 34.160.157.95:25...

curl -v telnet://smtp.mailgun.org:465
* Host smtp.mailgun.org:465 was resolved.
* IPv6: (none)
* IPv4: 34.160.157.95
*   Trying 34.160.157.95:465...

curl -v telnet://smtp.mailgun.org:587
* Host smtp.mailgun.org:587 was resolved.
* IPv6: (none)
* IPv4: 34.160.157.95
*   Trying 34.160.157.95:587...
* Connected to smtp.mailgun.org (34.160.157.95) port 587
220 Mailgun Influx ready

I even tried to set up a fresh instance on Railway (in case it was port 587, my nginx setup, my VPS in particular or my provider) but faced the same issue there using the Alpine image and port 465.

I’ve been at it for like a month. I’m hoping someone can point out what I did wrong so I can finally fix it :sweat_smile:

I might not be as smart as I occasionally think :joy: I may have figured it out after checking a tutorial from a 2022 post.

Mailgun domain is not the like domain I would use to call the Mailgun API. It’s the domain I set Mailgun up to use to send my emails. I’ll do some more testing to be sure.

Here’s the tutorial in case anybody else gets tunnel vision like I did: Self Hosting a Ghost blog with docker-compose, Mailgun setup, and Stripe subscriptions

From this post: Solution - Multiple Ghosts Instances on Digital Ocean Droplet - #5 by jazmy

And this comment specifically: Solution - Multiple Ghosts Instances on Digital Ocean Droplet - #6 by ajfriesen

1 Like

Even though the tutorial is a bit older, it’s still the way I host my ghost blog.

1 Like