Mailgun "The email service was unable to send an email batch"

Hey folks,

I am having trouble sending mails via Mailgun as a newsletter.
SMTP should work since I can register with other mail addresses as a member of the site and get a verification mail as well.

I am running a docker-compose setup. Using always the latest ghost:4 container with the latest MySQL:5.7 container. Watchtower will check every day if there is a newer image and change to that.

URL: https://www.ajfriesen.com

Ghost Version:

root@e079631b7d8d:/var/lib/ghost# ghost version
Ghost-CLI version: 1.17.3
Ghost version: 4.16.0 (at /var/lib/ghost)

Error in console:

[2021-10-02 19:35:38] INFO "PUT /ghost/api/canary/admin/emails/61578eb61b9ab90001846fdb/retry/" 200 163ms
[2021-10-02 19:35:38] WARN The server has encountered an error.

The server has encountered an error.

"The email service was unable to send an email batch."

Error ID:
    ec161420-23b7-11ec-9011-8bb0fcfb4687

Error Code: 
    BULK_EMAIL_SEND_FAILED

----------------------------------------

EmailError: The server has encountered an error.
    at /var/lib/ghost/versions/4.16.0/core/server/services/bulk-email/bulk-email-processor.js:240:30
    at processTicksAndRejections (internal/process/task_queues.js:95:5)
    at async Object.processEmailBatch (/var/lib/ghost/versions/4.16.0/core/server/services/bulk-email/bulk-email-processor.js:166:34)
    at async Promise.map.concurrency (/var/lib/ghost/versions/4.16.0/core/server/services/bulk-email/bulk-email-processor.js:98:17)

[2021-10-02 19:35:39] INFO "GET /ghost/api/canary/admin/emails/61578eb61b9ab90001846fdb/" 200 35ms

Error in mailgun console:

unable to connect to MX servers: - ajfriesen.com: connection failed: while dialing: dial tcp4 185.250.239.4:0->116.203.153.211:25: i/o timeout

All my DNS settings are verified by mailgun.

I am using this Mailgun domain in the ghost admin panel: https://api.eu.mailgun.net/v3/mail.ajfriesen.com
with the private api-key by mailgun.

Any idea what I am missing?

docker -compose setup if important
version: '3'
services:

  caddy:
    image: caddy:2
    restart: unless-stopped
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - $PWD/blog/Caddyfile:/etc/caddy/Caddyfile
      - caddy-data:/data
    networks:
      - docker-network

  ghost:
    image: ghost:4
    restart: always
    environment:
      # see https://ghost.org/docs/config/#configuration-options
      database__client: mysql
      database__connection__host: db
      database__connection__database: ghost
      database__connection__user: ghost
      database__connection__password: "${MYSQL_PASSWORD}"
      # this url value is just an example, and is likely wrong for your environment!
      url: https://www.ajfriesen.com
      mail__transport: "${MAIL_TRANSPORT}"
      mail__options__host: "${MAIL_HOST}"
      mail__options__port: "${MAIL_PORT}"
      mail__options__secureConnection: "${MAIL_SECURE_CONNECTION}"
      mail__options__auth__user: "${MAIL_USER}"
      mail__options__auth__pass: "${MAIL_PASSWORD}"

      
      # 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:
      - ghost-data:/var/lib/ghost/content
    links:
      - db
    networks:
      - docker-network

  db:
    image: mysql:5.7
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: "${MYSQL_ROOT_PASSWORD}"
      MYSQL_DATABASE: ghost
      MYSQL_USER: ghost
      MYSQL_PASSWORD: "${MYSQL_PASSWORD}"
    volumes:
      - ghost-db:/var/lib/mysql
    networks:
      - docker-network

  watchtower:
    image: containrrr/watchtower
    container_name: watchtower
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
    networks:
      - docker-network
    restart: unless-stopped


volumes: 
  ghost-data:
  ghost-db:
  caddy-data:

networks:
  docker-network:

By the looks of those logs I’d say the issue is on the Mailgun side…

  1. I don’t understand why Mailgun is dialling back to your server. Shouldn’t it do it’s own sending?
  2. I think your “Mailgun domain” should be set to mail.ajfriesen.com (that is, without the api.eu stuff before it).
  3. Can you try running their sample code to test the API? See https://help.mailgun.com/hc/en-us/articles/202464990-How-Do-I-Start-Sending-Email-
1 Like

@EmpiricalEE

The solution was Mailgun domain needs to be:
mail.ajfriesen.com instead of
https://api.eu.mailgun.net/v3/mail.ajfriesen.com

Not sure how I came up with this string. Now I could send 1 newsletter mail.

Thank you very much!

2 Likes