0

I have a VPS with a sendmail instance on it which is used to deliver mail from a few Wordpress sites that I host. The sendmail is on the same machine as the Wordpress sites and I'm keen to keep it that way for quicker local mail hand-off. The sendmail server listens only for local connections and is also firewalled from incoming connections.

Two of my clients use G-Suite and one uses Office 365. Both of these are capable of receiving mail to relay on, provided that they have been configured to trust the IP address of the machine sending. Others send directly and have whitelisted this server in their SPF records.

Is it possible to configure sendmail to automatically listen on additional ports and then smarthost the mail sent via a particular port onward to a particular service?

G-Suite has a single relay point (smtp-relay.gmail.com) whereas each O365 domain has its own unique domain example-com.mail.protection.outlook.com. I don't mind configuring each port/smarthost combination, but want to know if its possible, and if so, how to configure this.

For example:

  • mail incoming on 25: queued for direct delivery.
  • mail incoming on 26: relayed to smtp-relay.gmail.com
  • mail incoming on 27: relayed to example-com.mail.protection.outlook.com
  • mail incoming on 28: relayed to example2-com.mail.protection.outlook.com

I would then configure each of the mail sending instances to talk to a specific port:

  • Customer A: 127.0.0.1:25
  • Customer B: 127.0.0.1:27
  • etc.
  • So wordpress/sendmail needs to send email to these client domains? If so, you don't need to do anything different. The email to these clients should be sent exactly the same way it's sent for any other domain. – joeqwerty Sep 17 '18 at 15:12
  • The emails are not to the clients, they are on behalf of the clients to a wider public audience. – Philip Sep 17 '18 at 15:14
  • OK, so send the email directly to the recipients and have these clients add your server to their SPF record like you did for your other clients. What is the reason you're doing it differently with these particular clients? – joeqwerty Sep 17 '18 at 15:23
  • Mostly because then I don't have to concern myself with DKIM, DMARC etc. Also, Google, at least, then also automatically records a copy to the sending user's sent items. – Philip Sep 17 '18 at 15:25
1

Well, basically there are three ways to deal with this problem, as usual they are best, old-school and Jedi's :). The best way is to finally trash sendmail in 2018 and start using postfix or exim, where mail routing could be fine-tuned more easily.

The old-school way, and probably the one you're looking for, is to create separate sendmail.cf files for each incoming port you want to use, specifying listening port and appropriate smart-host in each of them, and run different sendmail daemons with each. That's what it used to be prior to 8.10 when sendmail was finally able to listen on multiple ports at once as a daemon.

The Jedi's way is to create a custom ruleset using sendmail.cf syntax where routing would be altered based on the value of $&{daemon_name} macro value, and set it's appropriate value for each listening port instance via DaemonPortOptions('Name=MyServerName') option (had to edit this because of backticks). That'll be probably a code section no more than 8 lines long, considering you'll be using a hash table to look up smart-host based on that value.

While the Jedi's approach is tempting, it's actually a dead end, as my own long experience with maintaining custom rulesets for sendmail shows that every three years since you've wrote it you'll be looking at it as if it was written by aliens..

So if you're really want to stick with sendmail and have your problem solved I'd recommend you stick to the old-school solution :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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