smtpsendmailemailrelay

Implementing an intelligent relay with an SMTP server/client


I need to implement an intelligent mailing list/relay (on Linux). The idea is that:

  1. The server receives emails to a list address
  2. It parses the mail, and confirms that it's from a trusted source
  3. It looks up a list of recipients in a local database
  4. It does some minor processing on the incoming mail, and sends it out to the list
  5. It returns any bounce messages to the original sender

The server already has sendmail installed, but I can use another MTA if necessary.

This sounds straightforward, and sendmail already has a database look-up capability. However, I don't think this is particularly flexible, and I don't want to give sendmail independent access to my database.

The closest I've come to an existing solution is E-MailRelay, which looks good, but I don't want the overhead of integrating it if I can avoid it.

I'd appreciate a sanity check on my Plan B before starting it, or alternative suggestions. I haven't found any useful docs on this and the Sendmail book doesn't seem to have anything relevant in it.

What I'm thinking about is:

  1. Implement an SMTP delivery agent for sendmail, and have sendmail and the DA running on the same server, with the DA listening on some unspecified port (which?)
  2. Sendmail presumably acts as an SMTP client when connecting to the DA, and my DA will respond to MAIL/RCPT/DATA commands
  3. The DA processes the received mail, which will be either a message out to the mailing list, or a bounce, or possibly a response
  4. The DA then switches to client mode, connects to sendmail, and issues MAIL/RCT/DATA commands to return the response to the original sender

Does this make sense? Thanks.


Solution

  • This turned out to be pretty straightforward, although I didn't use a sendmail delivery agent - I just did everthing in SMTP. The server has two IP addresses, and sendmail is already listening on port 25 on IP#1.

    I wrote an SMTP proxy which listens on port 25 on IP#2. This runs an SMTP server, which accepts incoming messages, and re-writes them. It then connects (as a client) to port 25 on IP#1, sending the re-written message to sendmail. sendmail then handles transmission to the re-written destination addresses. This is all transparent to the original mail client.

    Not sure how I'd do this if the server only had one IP address, though.