4

I'm working on a project that is email-intensive and I appreciate that the emails land in mailhog on DDEV, but I want to see them in gmail, Outlook, etc. How can I get them to where I want to look at them? (I use ddev launch -m to launch the mailhog browser in ddev; docs are at https://ddev.readthedocs.io/en/latest/users/developer-tools/#email-capture-and-review

rfay
  • 9,963
  • 1
  • 47
  • 89

2 Answers2

4

This isn't too hard to do, it's just that Mailhog's debug/error output isn't captured or presented by ddev, so it requires a bit of effort to get it working.

  • You need an smtp server that will accept regular SMTP traffic. These days, it will require a username and password. I used mailgun (https://www.mailgun.com/), which is free but requires a credit card. I'll assume you have this set up.
  • You need to be able to see the output from Mailhog as it tries to "release" the email. We'll use a ddev custom command to solve this.

Step by step:

  • Install this custom command to be able to see the output of mailhog. Put it in .ddev/commands/web/mailhog-debug and make sure it's executable (chmod +x .ddev/commands/web/mailhog-debug).
#!/bin/bash

## Description: capture debug from mailhog
## Usage: mailhog-debug
## Example: "ddev mailhog-debug"

set -eu -o pipefail

echo "mailhog on project d8composer"
sudo rm -f /etc/supervisor/conf.d/mailhog.conf # Remove mailhog from supervisor conf
kill -1 1  # Tell supervisord to reload
killall mailhog || true
mailhog
  • Send a message. This can be with the project's contact page or whatever your application is doing.
  • View the message in Mailhog (use ddev launch -m to launch the Mailhog interface).
  • Use the "Release" button to release the message into the wild: Mailhog release button
  • Enable mailhog debugging, ddev mailhog-debug - it will keep going until you
  • On the "release" form, you need to give it the credentials that you're going to use. You can click the "Save these settings" checkbox... but you must leave it unchecked the next time you are here or Mailhog will throw away your message saying it's already created that server. SMTP server settings for mailhog
  • Click "Release message" and watch the debugging go by in your terminal window. If you're like me you'll have a few authentication failures before you get it right.
  • Enjoy looking at the email at the target email address.
rfay
  • 9,963
  • 1
  • 47
  • 89
1

I'm using a recent version of DDEV (1.21.6).

I found I didn't need the custom command above. Mailhog recieved my mail fine, so I just clicked release and entered the details of my SMTP server and released the mail. It arrived in my inbox in seconds.

Alternatively, because my project uses Drupal 10, I installed the symfony_mailer

  • enable the module
  • add a SMTP transport using your mailserver settings
  • set it as the default
  • send a mail ("forgotten password")
  • receieved mail since it bypasses PHP sendmail function and uses SMTP instead.
tyler36
  • 131
  • 5