Local SMTP notification relay for security/performance using docker, maildev and gmail

Hey everyone, I’ve had a bit of help from several contributors when asking questions - not to mention the many other asked and answered questions which are searchable.

I had an old security camera that didn’t work with gmail smtp - but everything else did which was frustrating.

The solution that I have implemented is to use Maildev as a local relay which does work with gmail smtp service. It is running in docker via portainer on my HASSIO server. Maildev was chosen as it has a web interface, and has some API’s. I have also configured it as a mail notifier for ALL my email notifications now and it is working perfectly.

Part1: Set up maildev
The docker container is set up in portainer as follows, you can change the ports if you wish of course, I couldn’t get the variables to work as expected so I ended up putting most of the config in the command line. You really really should use a Gmail Application Password.
Main Settings:

name: SMTP-Relay
Image: maildev/maildev:latest
Manual Network port publishing:
host: 1025 -> container: 25
host: 1080 -> container: 80

Advanced Container Settings:
command: '--web' '80' '--smtp' '25' '--outgoing-host' 'smtp.gmail.com' '--outgoing-secure' '--outgoing-user' '<youraccount>@gmail.com' '--outgoing-pass' '<your application password>' '--auto-relay'

restart policy: Unless stopped

Once this is done you should be able to access the maildev console via http://yourdockerhost:1080

Part2: Set up Home Assistant Mail Notifier:
My configuration.yaml is set up as follows, note I have configured maildev with no authentication so no passwords are needed in my configuration.yaml.

notify:
  - name: house-outbound-email
    platform: smtp
    server: 192.168.1.201
    port: 1025
    timeout: 15
    encryption : none
    sender: <youraccount>@gmail.com
    recipient:
      - <youraccount>@gmail.com
    sender_name: <youraccount>@gmail.com

note: you need to reload core, and potentially all of HomeAssistant for some configuration.yaml changes to work

*Part3: Test mail relay notifier via Developer Tools


result in maildev:

result in gmail:

Part4: Keeping it tidy:
Lastly, maildev keeps everything until you manually or api-wise purge the mail relay box, you can visit the maildev web page and “clear mailbox” or…
You could do a scheduled task to clear it out using curl:
curl -X DELETE http://localhost:1080/email/all

Or in your configuration.yaml create a rest service and then create a daily/weekly/etc automation to activate the service

rest_command:
  purge_smtp:
    url: "http://localhost:1080/email/all"
    method: DELETE
    verify_ssl: false

Hope this helps anyone who is either still using email for notifications or just perhaps wanting to configure an SMTP relay.

Updated June 2022 to add “encryption : none” to the notify section.

5 Likes

Minor update!

the configuration.yaml section has been updated, it appears smtp notify turns on encryption by default, so you need to set
encryption : none

Thank you :+1: