Using port 587 with sendmail

48,703

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
define(`SMART_HOST',`relay.example.com`)dnl

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

# sendmail.mc
define(`SMART_HOST',`relay.example.com`)dnl
define(`RELAY_MAILER',`esmtp')dnl
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,
                  T=DNS/RFC822/SMTP,
                  A=TCP $h 587
  Mesmtp2525,         P=[IPC], F=mDFMuXa, S=EnvFromSMTP/HdrFromSMTP, R=EnvToSMTP, E=\r\n, L=990,
                  T=DNS/RFC822/SMTP,
                  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.

Share:
48,703

Related videos on Youtube

Archith
Author by

Archith

Updated on September 18, 2022

Comments

  • Archith
    Archith over 1 year

    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?

    • Admin
      Admin almost 10 years
      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?
    • Admin
      Admin almost 10 years
      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.
    • Admin
      Admin over 3 years
      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.
  • Archith
    Archith almost 10 years
    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?
  • Archith
    Archith almost 10 years
    Something like - sendmail -port 587 [email protected] < test.txt
  • HBruijn
    HBruijn almost 10 years
    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:[192.168.169.170:587]
  • Archith
    Archith almost 10 years
    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?
  • AnFi
    AnFi almost 10 years
    @HBruijn Could you provide link to smtp:[smtp.example.com:587] syntax documentation?
  • HBruijn
    HBruijn almost 10 years
    @AndrzejA.Filip Hmmm, just tried that and it fails miserably :) The solution is to define a new mailtransport and use that in your mailertable. I'll update my answer with that alternative.