The Problem

Have you ever wanted to setup notifications on something in your home lab, but then given up because it doesn’t support your tool of choice?

Well that was me. I wanted to setup notifications from a few of my apps and my NAS, which is running UnRaid, but they didn’t support Apprise API.

The Solution

To solve this, I developed Mail-2-Webhook, A simple SMTP server that takes emails and sends them to a webhook of choice. The default format is for Apprise, but I intend to add more customizations over time.

The Details

I knew of this package called Nodemailer from a past project. As it turns out, this email sending module written in NodeJS has an extra called smtp-server.

Surely enough, the SMTP Server module acts as an email server, listening for emails being sent over a configurable port but defaulting to 25. I did a little investigation and realized, that’s all you need to make this project happen. They also provide a Mail Parsing package that helps with pulling the formatted bits of data out and passing them along.

With those pieces, I got to work. Tinkering and testing every possible arrangement of parameters I could find. It turns out, email servers can be quite a pain to set up and most users of email servers expect some amount of proof of identity. What I mean by that is domain names and certificates. More on that later.

The basic design is the receipt of mail triggers a webhook. To implement this design I created the SMTP server with an onData function. In that function, I parse the email content and send it via the library node-fetch to my desired HTTPS endpoint.

Node-fetch acts a lot like the native fetch library of browser based javascript. Yes there are fundamental differences between web browsers and NodeJS and one of those is the built in library for calling HTTP endpoints.

With that setup, all you need is a valid URL that your server can reach and you’re off! In my case, I use my Apprise’s external URL which includes HTTPS and a valid cert for that domain but routes through my internal network since I resolve the DNS entry locally instead of sending it out to the internet and back. This works great for me because it allows me to retain Apprise’s local-only setup that prevents me from needing to secure it from the internet.

The last remaining piece was to log into UnRaid, go to the settings tab, find notifications, and enable email notifications with a custom email provider. From there, I was able to enter the hostname of my VM running the M2W server, set it to “no auth” mode, and put some phony email addresses. Luckily, it does not matter in my case what the sender/receiver addresses are because any email sent to this server will be forwarded to Apprise.

The Catch

I did not want to go through the hassle of setting up a real email server, that’s not the point of this project. The purpose was to be able to receive an email sent internally on my home lab, process it, and send the output to another service via HTTP(S). So I went the only sane route, disable all authentication and validation settings possible.

This is NOT a production grade email server. Do NOT think of it that way. This is a great, in-home tool for forwarding custom emails to a webhook server. I can only say it so many ways. Please do NOT expose this server to the internet and do not expect it to work over a public facing interface (mostly because ISPs block SMTP servers by default and it’s a good way to get yourself blacklisted).

If you want a production grade email server, look somewhere else. There are plenty of options out there that you can use to set one up and maybe I will cover those as a separate piece in the future.

All this to say, the server works for its intended purpose and I would recommend using it for that case alone. I plan to provide more flexibility with the webhooks as I previously stated and may investigate how to set it up with proper certs and TLS.