🐝 βœ‰οΈ MailHog & Wasp: Testing Emails Locally

medardm

Medard Mandane

Posted on July 26, 2024

🐝 βœ‰οΈ MailHog & Wasp: Testing Emails Locally

What is Wasp

I'll assume you already know Wasp, it's basically a Full-Stack framework similar to Laravel but for Javascript. If you don't know anything about it yet, then I guess this is a sign that you should start exploring now.

For more information, please check their website -> Wasp-lang. Please read about OpenSaaS as well.

What is MailHog

  • Mailhog is an open source email testing tool that works locally. That only means you don't need internet to test emails.
  • To install MailHog, please check their GitHub repository for more info

How to use MailHog in Wasp

Step 1: In main.wasp file

  • set the email sender provider to SMTP
// main.wasp file
emailSender: {
...
  provider: SMTP
...
}
Enter fullscreen mode Exit fullscreen mode

Step 2: Update .env.server

  • To use MailHog, simply set the SMTP configuration with the following values:
SMTP_HOST=localhost
SMTP_PORT=1025
SMTP_USERNAME=mailhog
SMTP_PASSWORD=mailhog
Enter fullscreen mode Exit fullscreen mode
  • Usually you don't need to set the SMTP_USERNAME and SMTP_PASSWORD, however this won't work as Wasp uses nodemailer and the secured option is set to true by default if not specified.
    • Currently, there's no way to override that option. This works because I also don't know, maybe it's related to encryption or some restriction of nodemailer. Maybe you can help me explain it more 😁

Step 3: Testing

  • Open the web interface of MailHog, this is where you will receive all the emails sent through Wasp, you can access it @ localhost:8025 or 0.0.0.0:8025
  • Try sending an email, if you are using the OpenSaaS template, you can simply try reset password.

opensaas template reset password

  • You should receive the email email received in mailhog

If these instructions doesn't work and you found a working solution, please let me know :) I only tested this on a mac machine

πŸ’– πŸ’ͺ πŸ™… 🚩
medardm
Medard Mandane

Posted on July 26, 2024

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related