cosullivan / SmtpServer

A SMTP Server component written in C#
MIT License
675 stars 159 forks source link

Using SmtpServer as a SMTP Filter for SPAM #216

Open alijundi opened 2 months ago

alijundi commented 2 months ago

Hi @cosullivan

I thank you for this wonderful library,

I want to use it as follows in my company. Email comes in to the SMTP Server using this library and then forwarded to another SMTP server where emails are stored.

It will check the incoming message if it is spam and modify the subject by adding SPAM before it and then it will immediatly forward it to the specified SMTP server.

Can you direct me on how to implement this. I believe it should not be too hard. Don't worry about the SPAM function it will will take the TO/FROM/SUBJECT/BODY of the message to decide whether it is SPAM or not and then return true/false to the calling check function.

mormegil-cz commented 1 week ago

It seems fairly straightforward, doesn’t it? You just start the SmtpServer and configure an appropriate IMessageStore (and possibly a IMailboxFilter if you know existing recipients). The store implementation will just forward the message to the destination SMTP server (using e.g. MailKit’s SmtpClient).

Even though you might want to use store-and-forward instead of directly forwarding synchronously inside the incoming SMTP transaction, I think. I.e. create a simple Sqlite (or any other) database and store all incoming messages there in the IMessageStore implementation. Then, have another worker asynchronously fetch the messages from the database and send them to the destination SMTP server.

In fact, I’m working on something very similar, even though not specifically as a spam filter.

(P.S. This might better be a discussion instead of an issue?)