Using Ghost with Mailhog for local newsletter testing

Hi folks,

I often use Mailhog for testing of emails without needing to send actual email through a service like mailgun, and it seemed worth sharing here.

What’s Mailhog?

Mailhog is an easy to install tool, that acts like an email server, letting you send email to a ‘fake’ inbox, so you can get an idea of what emails look like without needing to send them through the internet.

It’s based on the earlier Mailcatcher, which is where I pilfered this screenshot to give an idea of what these kinds of tools do:

However, being a single go binary, it’s easier to install and use, and you don’t need to know much about python to use it:

Using Mailhog and Ghost for testing emails.

You can use Mailhog to test sending emails, without needing to connect to the internet, if you’re on a train for example, or you’re working on templates, and need to send a few emails as a sanity check, and don’t want to cruft up your inbox:

First install Mailhog. On OS X, it’s brew install mailhog.

Then update config.development.json, to replace this:

"mail": {
    "transport": "Direct"
  }

With this:

"mail": {
    "transport": "SMTP",
    "options": {
      "host": "0.0.0.0",
      "port": 1025
    }
  },

And you should have easy local email testing!

This is also useful if you locked yourself out of your development environment like I just did, and forgot the password you used to get in…

Hope this helps some other soul, or even future me, when I forget and search in six months :slight_smile:

This is really really useful. Thank you for this little snippet. I’ve incorporated this into my docker stack for my ghost website. Not sure if anyone else will find this useful but here it is if anyone finds value in it:

version: "3.7"

services:
  ghost:
    networks:
      - shared_backend
    image: ghost:3.38.3
    ports:
      - "8888:2368"
    restart: always
    env_file: .env
    volumes:
      - ./content:/var/lib/ghost/content/
  mysql:
    container_name: shared_mysql
    image: mysql:5.7.29
    restart: always
    env_file: .env
    networks:
      - shared_backend
    ports:
      - 3306:3306
  mail:
    image: mailhog/mailhog:v1.0.1
    container_name: mail
    ports:
      - 8025:8025
    networks:
      - shared_backend
      

networks:
    shared_backend:
        name: shared_backend
        # use a custom driver, with no options
        driver: bridge

env file:

## Database Ghost config
database__client=mysql
database__connection__host=shared_mysql
database__connection__user=root
database__connection__password=testing
database__connection__database=ghost

## Domain config
url=http://0.0.0.0

##MySQL config 
MYSQL_ROOT_PASSWORD=testing 
MYSQL_DATABASE=ghost

## MailHog Settings TESTING ONLY
mail__transport=SMTP
mail__options__port=1025
mail__options__host=mail

You’ll be able to load the browser with: http://localhost:8025 to see your mailhog emails and http://localhost:8888 for the ghost site.

Wow, I use MAMP Pro to run MailHog server, replace Amazon SES with your exact configuration, and it works great. No need to check REAL email.

Thank you.