I'm working for a company that will be renting smtp server capacity similarly to MySMTP. Our end users use a 3rd party email marketing frontend application configured with the details of our SMTP gateway to send emails. These frontend applications do not support custom HTTP APIs and only work over direct SMTP protocol.

As always with email related services, spam and abuse are very real concerns for us. Therefore we will need some processor component for filtering out suspicious content, checking user credits and sending the received mails through multiple different SMTP servers to provide faster processing for multiple users and hopefully avoiding problems related to excessive volume with ISPs.

So my question is, how can I receive emails to a PHP or Java preprocessor program via SMTP protocol and then send/forward it through another SMTP server?

A few minutes of search provided me with http://emailrelay.sourceforge.net/. This seems like the thing I'm looking for, except it has a couple of problems:

  • It looks like it can only be statically configured to forward to a single smtp server.
  • I would like to leverage a more "powerful" filtering method than javascript. For example, PHP or Java. The filters need to be configured dynamically from administrator panel (accessible from cloud) due to changes in spam patterns.
  • It's likely that the system will have it's own frontend service sometime in the future, which would need to be able to communicate with this processor component.


How can I get a preprocessor program to intercept SMTP requests before any email is sent by the SMTP server and then forward it trough another SMTP server?

  • The "pros and cons" is not the question in itself, it's merely a request to broaden the answer provided to the original question. For example: if it's possible to do this, would it be considered a bad practice? Would it be terribly slow with volume? Perhaps I should of simply asked for the downsides since otherwise I only want it for my convenience and that is the "pros".
    – Nonetallt
    Feb 8, 2017 at 12:44
  • 1
    While it is possible to write your own spam filter, getting to where it is any good is a very long way. One example in real life a friend of mine often send mails with the subject "Ups" (danish for Oops) when he bought new dvds. The spam filter on his mailserver rejected my replies due to the subject being "Re: Ups" a common phishing subject. The large company that had made that spam filter missed the fact that that could indeed be a valid subject.
    – Bent
    Feb 8, 2017 at 13:14
  • 1
    While there are good questions in this, I think it currently is too broad, and part of it might belong on security stackexchange. Maybe you could split the question up in several questions that are easier to answer.
    – Bent
    Feb 8, 2017 at 13:17
  • You make valid points. However I find it hard to address this problem while narrowing the subject without losing context. It is not my intention to create a brand new all inclusive spam filter, I trust that spam assassin and other such measures are taken by most inboxes by default. I am more concerned about patterns as in invalid addresses, volume and throttling overall sending when something looks suspicious.
    – Nonetallt
    Feb 8, 2017 at 14:25

1 Answer 1


You are probably overthinking it a bit.

It is not entirely clear from your question, but I assume that your company has a couple of SMTP servers and will be giving out/selling accounts to your customers to send (legitimate) bulk emails.

From the viewpoint of an SMTP server, there is no real difference between what your customers will be doing and what you are doing when you send a few work emails (using your work email address) from your phone or when working from home, except that your customers will send their messages to more recipients at a time.

All major SMTP server applications can handle the authentication/authorization of your customers without problem. Most of them also have the possibility to configure filtering options for both incoming and outgoing messages, including calling external programs to do the filtering.

TL/DR: Don't try to get in front of your SMTP server, but use the capabilities is has for calling external programs to do the filtering you need.

  • Thanks for the suggestion, it looks like Postfix servers do indeed have options to configure filter and receive webhooks to PHP scripts. Using those I can indentify the users and keep track of their credits and the volume of emails sent. I'll look into it and confirm the answer.
    – Nonetallt
    Feb 9, 2017 at 14:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.