Sendmail – Configuring Sendmail to Listen on an Alternative Port

sendmail

I've set up sendmail to listen on port 1234 rather than 25 with one change to sendmail.mc:

DAEMON_OPTIONS(`Port=1234, Name=MTA')

This generally works, with one exception. The background is that I have a relay listening on port 25 (the relay must have an MX record, so it must be on port 25). The relay sends on mails via sendmail, so sendmail listens on localhost:1234. In other words, sendmail is only responsible for sending mails, and not receiving them. netstat/etc confirm that the relay is listening on 25, and sendmail is listening on 1234.

This works in these two test cases:

  1. I can send emails by telnet'ing to sendmail (telnet localhost 1234)
  2. I can send emails from s-nail with an appropriate configuration change (set mta=smtp://localhost:1234)

However, this setup doesn't work if I run sendmail directly:

sendmail -d8.20 -vt < test-email.txt

In this case, sendmail tries to send the mail by connecting to port 25 locally, so it actually talks to the local relay, rather than a remote SMTP server. The debug output shows:

[email protected]... Connecting to [127.0.0.1] via relay...
220 mydomain.org ESMTP mydomain relay

This has got me stumped – any idea what's going on here?

EDIT

Making some progress. I'm on Sendmail 8.15.2, Ubuntu 20.04. This problem wouldn't really matter, except that sendmail flushes its MSP queues with a cron job that runs every 20 minutes, so I get a lot of syslog failure entries, and big queues of undeliverable email, because sendmail can't find itself.

The problem seems to be as follows. When you send a mail (or manage the queues) using sendmail, it is (normally) a 2-step process. You run sendmail, which reads submit.cf (and not sendmail.cf), and acts as an MSA, submitting the mail to something. That something is normally the local sendmail daemon, which reads sendmail.cf when it stats up.

sendmail.cf tells sendmail that it needs to listen on localhost:1234 for incoming mails. This means that submit.cf must contain a config which tells the sendmail program to route outgoing mails to localhost:1234.

The relevant submit.mc config is probably FEATURE msp, which defaults to

FEATURE(`msp', `[127.0.0.1]', `25')

So the answer is probably as simple as changing 25 to 1234. However, it's not that easy. Just changing it, regenerating the files, and restarting sendmail, makes no difference. In fact, regenerating submit.cf with either m4 or make either makes exactly zero difference, or gives you a cf file with the feature commented out. There's some magic somewhere which lets you change the feature, but I have no idea what. The answer may be in /usr/share/sendmail/cf/feature/msp.m4, but I can't see it.

Best Answer

Running sendmail from command line, it using a different configuration file.

Edit the file "submit.mc"

add the line:

define(`RELAY_MAILER_ARGS', `TCP $h 1234')dnl

before the line:

FEATURE(`msp', `[127.0.0.1]')dnl

Then compile "submit.mc" to "submit.cf".

Related Topic