I have been using sendmail to send out mails using internally available mail server. But currently port 25 is blocked for security reasons.

I would like to know if there is a way to specify port number in the sendmail utility. I am trying to make use of the secure SMTP-MSA port 587 as an alternative assuming I could get that port opened up.

I was not able to find anything in the man pages for sendmail. Is there any alternate utility that could do this?

  • 3
    You are trying to circumvent an organization's IT security rules? Good idea? Why not first ask those who are responsible what to do about it? Commented May 30, 2014 at 14:01
  • 2
    Port 587 is a recognized secure port and could only be used if it is allowed to. I do use them for windows services running on various servers.
    – thinkster
    Commented May 30, 2014 at 14:11
  • So I am focusing on the subject of sending mails using port 587 using a utility like sendmail.
    – thinkster
    Commented May 30, 2014 at 14:23
  • 1
    I can't understand ignorant trolls that complaint about using a different email ports. This is a normal practice for many ISP, some organization, like mine, also open specific email ports for users and applications.
    – fcm
    Commented Sep 19, 2020 at 10:55

2 Answers 2


Unless explicitly configured otherwise, mail will be transmitted over port 25.

You can route mail using other ports, or even other protocols than SMTP but that will typically only work within your own network. The mailservers from your intended recipients will most likely only accept incoming email via SMTP on port 25.

For instance when I configure sendmail to listen to port 587 it will typically only accept incoming e-mail over that port when the user has authenticated.

 DAEMON_OPTIONS(`Port=submission, Name=MSA, M=Ea')

Most networks that restrict incoming and/or outgoing SMTP traffic (a good and common practice for both consumer ISP's and corporate networks to prevent open mailrelays, spam and other abuse) provide relay servers, allowing you to send mail, but not unrestricted. Relay servers may check content (viruses, spam) or enforce policies (adding the standard disclaimer, archiving messages for compliance, restricting recipients) etc.

If you're provided with a relay server; in sendmail that is called a smarthost and configured in

# sendmail.mc

If your relay server is listening on a port 587 that becomes:

# sendmail.mc
define(`RELAY_MAILER_ARGS', `TCP $h 587')dnl

The assumption is that sendmail forwards all your email traffic to the relay which transports the messages to the intended recipients and the relay server not requiring authentication.

You can fine tune your email routing with the mailertable.

To route some email domains to one remote TCP port and mail for other domains to another requires some editing in the sendmail.cf to set up a new mailer. Copy the settings from the existing esmtp mailer and add a port number:

  # sendmail.cf
  # <snip>
  Mesmtp587,         P=[IPC], F=mDFMuXa, S=EnvFromSMTP/HdrFromSMTP, R=EnvToSMTP, E=\r\n, L=990,
                  A=TCP $h 587
  Mesmtp2525,         P=[IPC], F=mDFMuXa, S=EnvFromSMTP/HdrFromSMTP, R=EnvToSMTP, E=\r\n, L=990,
                  A=TCP $h 2525

transport channel esmtp587 will now deliver to port 587 instead of the default 25 or and similarly to 2525 or whatever alternative port you specify.

Then in your mailertable:

 example.com    esmtp587:example.com
 example2.com   esmtp2525:example2.com

The line above will allow sendmail to look up the MX records for example.com, if only a single (relay) smtp server for example.com supports the non-default port the syntax will become:

 example.com   esmtp587:[smtp.example.com]

The brackets tell sendmail to ignore possible MX records for smtp.example.com and to route all mail for @example.com to smtp.example.com:587.


sendmail.mc file entries:

dnl   Modify relay mailer to make it connect to port 587 instead of 25
define(`RELAY_MAILER_ARGS', `TCP $h 587')dnl
dnl   Define relay for non local email
dnl   Use [] to disable looking up for MX records
define(`SMART_HOST', `relay:[name.of.smart.host]')dnl

Sendmail FAQ 3.39 : How do I send using an alternate port?

P.S. You may use FEATURE(mailertable) to specify different relay for specific non local email domains.

  • Cool, yeah I was reading through that. But what if I had another port? Lets say I have port 25 and 587 available to send mail. Do I get an option with sendmail or any other similar Linux utility to specify port number to use while triggering the mail?
    – thinkster
    Commented May 30, 2014 at 15:34
  • Something like - sendmail -port 587 [email protected] < test.txt
    – thinkster
    Commented May 30, 2014 at 15:35
  • In the mailertable you can add a port number for a specific domain IIRC, example.com smtp:[smtp.example.com:587] or maybe example.com smtp:[]
    – HBruijn
    Commented May 30, 2014 at 15:46
  • Got it. But as you had mentioned in your previous reply I do see a relay server entry with SMART_HOST. Since I am concerned about sending mails and not receiving from an application standpoint. I believe following changes would be enough to make the application send mail from the Linux server: define(SMART_HOST',relay.example.com)dnl define(RELAY_MAILER',esmtp')dnl define(RELAY_MAILER_ARGS', TPC $h 587')dnl` And I believe as far as the switching of port goes I believe I cannot do it on a conditional basis except based on domain names?
    – thinkster
    Commented May 30, 2014 at 15:58
  • @HBruijn Could you provide link to smtp:[smtp.example.com:587] syntax documentation?
    – AnFi
    Commented May 31, 2014 at 21:53

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .