cosullivan / SmtpServer

A SMTP Server component written in C#
MIT License
692 stars 163 forks source link

generic email webhook service? #148

Closed adamfoneil closed 3 years ago

adamfoneil commented 3 years ago

This may be a dumb question, but I'm having a hard time finding info about doing something I want to do. I want to do something like what this service does: https://www.email2json.net/

I'd like to be able to send email to a domain I control, then have some listener recognize incoming messages and call webhooks that users have created. These webhooks would receive json POSTS of the original email data. The idea here is to enable loosely-coupled email-based automation for, as an example, a CRM app that needs to track emails in a certain way. The end user would only need to know a special email to send to in order to trigger some automation. (This way, they can use whatever mail client they want.)

I'm familiar with Azure Function apps, and I was hoping there was some way to leverage those in this case, but I don't know how that would work here. There's no SMTP trigger for Function apps. (There's a SendGrid trigger for outgoing message, but I specifically want to monitor for incoming messages.)

SendGrid has an Inbound Parse feature that seems to be what this is for, but I don't really like doing anything with SendGrid. I just don't find them simple enough to deal with. But maybe that's just me.

I looked at the example code in the repo, but I didn't really get a sense of how to run the examples as part of a deployed solution. I'm sure this is because this is out of my comfort zone. Hope my question makes sense.

cosullivan commented 3 years ago

Hi @adamfoneil ,

I actually looked into this partially a while back and it can be done by writing a custom Azure Function Trigger. By defining a custom trigger, you eventually have to implement an object that implements the IListener interface which has StartAsync and StopAsync methods. Within this implementation, you could theoretically start and stop an instance of the SMTP Server.

However, there were a few questions that I hadn't answered when I stopped looking;

Failing that, the other approach would be to run a SMTP server instance separately and have that push messages to an Azure queue that are then picked up by the function app.

Thanks, Cain.

adamfoneil commented 3 years ago

Thanks for the feedback! This gives me some ideas