Built-in mailhooks for triggering workflows by sending mail

The idea is:

A node which offers a built-in mailhook, i.e. a uniquely generated email address to which emails can be sent in order to trigger a workflow, just like make.com offers (see also their docs on custom mailhooks):

Why workarounds aren’t good enough

This has been requested several times previously, but the typical response of suggesting to use some kind of workaround all have significant drawbacks.

For example, the suggested workaround of using the IMAP node to listen for new emails on a IMAP mailbox has some severe issues:

  • It only works if IMAP is available.
  • It requires picking one of three undesirable approaches:
    1. giving the workflow full access to read all incoming mails via IMAP, which is a huge compromise on security and privacy, or
    2. setting up dedicated IMAP accounts for each workflow, which creates a lot of UX friction, or
    3. setting up a shared IMAP account which handles incoming email for all workflows, but then you have to set up some filtering or routing so that only the right workflow is triggered for each incoming email.

Similarly problematic is the suggestion to use a third-party mailhook service:

  • Those require substantial extra time to set up. Compare with the make.com solution above where it’s a single mouse click to create a new mailhook email address.
  • Those third party services are typically very expensive for this very small feature.
  • Again it requires sending email to yet another third party, which is a further compromise on security and privacy.

My use case:

There are countless use cases, since countless systems send various forms of notification via email and don’t allow programmatic access to the data sent via email. Here are a couple of examples I have wished for recently:

  1. Notion does not support webhooks, so you cannot trigger workflows for events like someone commenting on a page, or mentioning you in a page. Currently this leads to ugly partial workarounds such as expecting users to click links within Notion to trigger workflows, or third-party services which fill the gap by requiring you to give them full API access to your Notion, which is a security and privacy nightmare.

    However, Notion does send email notifications for these kinds of events, so if they could be auto-forwarded to a custom mailhook, then automations triggered by those events could easily be built.

  2. Email newsletters could be automatically fed into an AI node which summarises them and/or extracts data into a more useful format. For example, a newsletter listing upcoming events could be converted into an iCalendar / ICS feed and uploaded to a webserver.

Any resources to support this?

Relevant resources have been provided as hyperlinks in the above text.

See also previous posts:

and

Are you willing to work on this?

I would love to find the time to work on this; unfortunately there’s almost zero chance I’ll have enough free time in the next 6-12 months. I could probably help with testing though.

Don’t forget to vote yourself :slight_smile:

Also, I hope you realise that if this eas implemented it could never be implemented for self hosted instances of n8n.

I do like the idea though, it makes things a lot easier for some usecases.

1 Like

Oops, thanks for the reminder :stuck_out_tongue_winking_eye:

Why not?

How would that work? Someone has to own the domain and mailserver and set everything up. That would be n8n if you want it without any/minimal setup for the user.
That can work on n8n cloud like you have with make (which is cloud only)
But if you self host, how does that work? N8n then has to create some kind of forwarding service to self hosted instances. Which costs them resources to build,maintain and run.
And then the self hosted instance needs to be setup exactly right to have it work properly. So n8n will get more support requests as well.
And at the end of it all they would do it for free for the community edition?
That is not going to happen, so they charge something for it. And then you can also use a 3rd party service.

Yes, unless they’ve already done that. For example I’ve been running my own domain and mailserver for about 20 years, so it would be easy for me to tweak it to support custom n8n mailhooks being handled by one of my existing domains.

No they don’t. It can simply be the responsibility of the user to self-host the mail domain and server as well, or to pay some other service to do that. Anyone who is capable of working out how to self-host n8n is also capable of working out how to self-host a mail server. Also as with any self-hosted service, the deployment processes can be further simplified and automated via the usual tricks, e.g. PaaS templates such as docker-compose, Kubernetes, VM images, or via SaaS solutions.

If they don’t see any business value in doing that, they don’t have to do it. Or if they do, they can. Simple.

Yes, but this is the responsibility of the self-hoster, just like with self-hosting n8n itself.

They don’t need to answer support requests for services they aren’t providing :slight_smile:

I’m certainly not expecting that. It probably wouldn’t make any sense as a business model, and it’s not even necessary. Self-hosters can self-host without receiving support, and those who want to skip the extra effort run in the cloud can pay n8n. There’s absolutely nothing new here relative to the n8n business model which is already in place.

1 Like

I might be missing something. How would it work then? How would n8n connect to the emailbox?
There is a couple of standard. But you basically already said you don’t want to use IMAP for example.
So I am missing what the feature would look like if not hosted as a service. As a service like that would basically just receive emails and send webhooks with the contents of the emails.
But connecting to the mailbox to read those emails is the tricky part if it is all going to be managed by the self-hosters.

Might be completely missing some kind of feature of emailboxes that could be used.

Ps. I am not trying to be negative, just do not see a user friendly way of doing it without providing a service around it.
And if it is not going to be user friendly, what is the point as there is other options then like IMAP.

I think it would be quite simple to achieve.

Sketch of implementation architecture

For example you configure your SMTP server so that any addresses matching a certain format (e.g. mailhook-<UUID>@mydomain.com where <UUID> is some randomly generated alphanumeric string) would be forwarded via a simple script to a helper service listening on a particular TCP port, and then that service would examine the recipient address and figure out which workflow to trigger.

I asked Gemini AI how to do this in postfix and the answer was pretty straightforward: https://g.co/gemini/share/cfdcda400c5e. Of course LLMs hallucinate so it might not be 100% correct, but based on what I know about postfix it looks reasonably plausible.

Really the only tricky bit is the routing of incoming email to the correct workflow. n8n would need to keep track of the mapping, e.g.

and so on.

A possible no-code mockup

In fact, I’m guessing all of this could probably be achieved even without writing any code:

Email → SMTP server → forwarding script → webhook triggering a router workflow → Execute Workflow Trigger runs the desired final destination workflow

In more detail:

  1. Any mail sent to mailhook-<UUID>@mydomain.com is forwarded via a simple script to an n8n webhook.
  2. That webhook triggers a router workflow which figures out from the recipient address which destination workflow the email is intended for, and uses an Execute Workflow node to forward the email’s data to the desired workflow.
  3. The desired workflow is triggered via an Execute Workflow Trigger.

I’m brand new to n8n so I might have messed up some details, but hopefully the general idea is sound.

The value of implementing a new mailhook node

The main value of adding a new mailhook node to n8n would be to eliminate the need for the user to set up step 2 in the above no-code approach, since n8n would itself know how to handle the routing to the correct workflow based on the address the email was sent to.

The value of it is no question. I would love to be able to use it.
The issue is the implementation.
As far as I know you can only send emails with smtp. That is why you have an IMAP node to use and you can also use for example gmail nodes that use the API to retrieve emails.

I googled it quickly “You can’t use smtp to read email, you need to use imap. pop3 won’t help because it only lets you read the Inbox.”
This is the first answer I got. Might of course be wrong but is in line with what I thought, so there is no reason for me to doubt it.
email - Read sent mails using smtp java - Stack Overflow.

So yeah I agree with you that it would be an awesome feature. But unless n8n is introducing a service (which there is also 3rd party services for) I don’t see a way to implement this without an IMAP for example. And then u can also just use IMAP directly.
Of course on n8n cloud I could see a service like this happen as it also might help get more people from make and such to n8n.

I think you are maybe misunderstanding that info. SMTP is a protocol for delivering mail over TCP/IP. There are SMTP clients which send mail, and SMTP servers such as postfix / exim / sendmail / qmail, which receive mail and decide what to do with it. Every single SMTP server I’ve ever set up (including the above 4) lets you configure it to take email sent to given addresses and forward that email to an external executable. (See the Gemini link in my previous post for suggestions for how to do this in postfix.) So I am saying that we could have a simple external executable which forwards the email to n8n and activates a mailhook trigger. I don’t know exactly how n8n nodes are available to listen on a TCP socket, but it must be possible because the Webhook node does it. I had a quick look in the source code and found this:

That seems to be where incoming HTTP requests are handled, but I couldn’t immediately figure out where the service is set up to listen on a TCP port. In any case, the mailhook node would work very similarly to the Webhook node, except that the routing would be based on the email recipient address instead of the webhook endpoint.

I think there is another feature request for this somewhere, in theory implementing this isn’t that tricky but it will be complicated for some set hosted users to set up the MX records that may be required.

I found two previous posts and they are linked from my original post above.

Typically (and indeed in my case) the self-hoster will already have their own domain set up with the necessary MX records. I think the main piece which will always be needed is configuring the SMTP server so that it forwards emails matching a certain recipient pattern to the n8n mailhook node. Of course if the self-hoster desires to keep all mailhook addresses on a subdomain like @mailhooks.mydomain.com then that would require an additional MX record, but that seems like a minor cosmetic issue and not really necessary.

Ok, that is where you have more experience than me. Your reference to an LLM answer makes me doubt your actual experience, as this is often done by users that have no actual experience. :slight_smile:
Still what you describe sounds not so easy to do for most, and there isn’t a lot of people setting up their own SMTP server. So this feature would then only be useable to very few users it seems.
If you want you can of course create the feature into a PR and the n8n team might add it to n8n. :slight_smile:

Haha, true :stuck_out_tongue_winking_eye: I’ve done plenty of SMTP server configuration over the years. But my personal server (running postfix) has been running in a stable configuration for a very long time, so I don’t tend to need to have all the details fresh in my head. Besides, LLMs are sometimes a decent substitute these days for reading dense technical manuals and trying to join the dots between different topics in order to get something done.

However in this case, the details of the exact config needed for a given SMTP server really aren’t important. The important bit is that every decent SMTP server under the sun allows forwarding of email data onto local executable processes, which means it’s possible to forward them onto n8n in whatever way n8n needs for this whole architecture to work.

Actually it’s easier than ever these days, thanks to IaaS and PaaS platforms coupled with deployment templates. Of course it’s not as simple as SaaS, but then neither is self-hosting n8n, and yet still people do it.

It’s usable to whomever is willing to put in the effort. And I strongly believe that anyone willing to put in the effort to self-hosting n8n is also easily capable of self-hosting an SMTP server. Not only that, but deployment templates for self-hosting n8n could be extended to include the necessary SMTP server configuration, to further minimise the effort required.

In my personal experience, setting up inbound mail servers was only ever in the hobby domain for me. It was far more work and upkeep to justify the cost savings for a professional provider ($1-5/mo/account).

With MX records, you may be able to simply parse out the email data into a JSON in n8n. I guess that would be an ideal outcome. But what about the actual email? And all the other components of the email server? It seems there may be more behind the MX records than simply updating a DNS record. But alas, I am also not the expert with the answer on that. My domain is outbound :sunglasses: