Local Email Development Service

in #development4 years ago (edited)

Whenever I've worked on any application that sends out emails it's always an issue on how to mimic the behavior on my local laptop. Usually wherever the app is deployed is configured to be able to just 'work'. aka you can send email by connecting to localhost with no auth.

Now, how do I mimic locally? In the past i've tried setting up postfix etc in a docker stack, or more recently doing an smtp relay using google services.

For reference the previous pattern:

#!/usr/bin/env bash 
docker run --restart always --name mail \
    -e RELAY_HOST=smtp.gmail.com \
    -e RELAY_PORT=587 \
    -e RELAY_USERNAME=user \
    -e RELAY_PASSWORD=secret \
    -p 25:25 \ 
    -d bytemark/smtp

This pattern requires you to enable unsecured application in your google account.

The new pattern I've started using of late is leveraging the wonderful tool called MailHog.

To set it up simply add the following to your docker-compose.yml file.

  mail:
    image: mailhog/mailhog:v1.0.1
    container_name: mail
    ports:
      - 8025:8025
      - 1025:1025

If your application is running in docker you don't need to expose 1025, if you're running your app outside of docker, you need to get to 1025 to send mail.

don't forget to bring it up via docker-compose up -d mail

At this point you just need to configure your SMTP settings.

Here's an example snippet that I used for my app.

reporting:
  to: [[email protected]]
  from: "[email protected]"
  subject: "Report for things"
  hostname: localhost
  username:
  password:
  port: 1025

Main parts you should note is the hostname is localhost, and port is 1025.

Then once everything is done you can connect to port 8025 and retrieve your email.

MailHog Screen

Sort:  

That sounds like a useful tool. Testing stuff in a safe environment before deploying is essential. I know email can have some quirks and setting up a server is tricky.

here.You should use the #stem tag and possibly #stemgeeks on these posts. That may reach a wider audience and can earn extra tokens. You would see those

!PIZZA

Connect

Trade


$PIZZA@csgeekdev! I sent you a slice of on behalf of @steevc.

Learn more about $PIZZA Token at hive.pizza

Thanks @steevc I'll do that in the future, doesn't seem like I can fix published posts.

You should be able to edit the post and tags. The only limitation is that you cannot change the first tag as I think that is intended to set where the post appears. How are you accessing Hive? Peakd is my preference as it does more than hive.blog.