Sendmail remote connection refused
Posted November 30th, 2003 in Email Servers (Updated May 24th, 2005)
If you can connect to sendmail locally but not remotely then you need to modify the sendmail configuration slightly. For normal workstation use, you would not want sendmail to be opened up for remote connections but would if it is being used as a mail server. (Note remote connection issues can always be firewall related).
You can test connecting to sendmail locally by issuing the command
telnet localhost 25
Note that we are not actually telnetting but attempting to establish a connection on port 25, which is the port mail transfer agents listen on for incoming connections.
If you get something like the following then you were successfully able to connect. To disconnect from sendmail type "quit" and hit enter.
Connected to localhost.
Escape character is '^]'.
220 laptop.electrictoolbox.com ESMTP Sendmail 8.12.8/8.12.8; Sun, 30 Nov 2003 13:19:45 +1300
If you could not connect then you'll see something like the following instead. If you get this then you probably don't have sendmail running, or the appropriate entry in your inetd or xinetd settings, depending on how your machine is configured. Fixing this sort of problem is not within the scope of this article.
Trying 127.0.0.1...
telnet: connect to address 127.0.0.1: Connection refused
Whether attempting to connect to a local or remote server you will get the same sort of result, either the connection will be refused or you will be greeted by the mail server. To allow access to incoming remote connections, you need to modify the sendmail configuration.
There are two ways to modify sendmail's configuration file. The sendmail.cf file contains all the instructions sendmail needs to run as you intend it to. It is generated automatically from the sendmail.mc file, which is a much easier to read and understand configuration file. Whereever possible you should always modify the snedmail.mc file rather than the sendmail.cf file. However, the are circumstances when someone has changed the sendmail.cf file manually and therefore you need to edit that again to prevent overwriting their changes.
sendmail.cf
To modify sendmail to accept remote connections in the sendmail.cf file, comment out (or deletd) the following line:
O DaemonPortOptions=Port=smtp,Addr=127.0.0.1, Name=MTA
The commented out version of this line would then look like so:
#O DaemonPortOptions=Port=smtp,Addr=127.0.0.1, Name=MTA
Restart sendmail after doing this and you should now be able to connect to sendmail from a remote machine. If you commented out the line rather than deleted it you are then able to easily revert back to your previous configuration.
sendmail.mc
The preferred option is to edit the sendmail.mc file instead. It's always a good idea to make a backup copy of the sendmail.cf file though in case something goes wrong and there had been changes made to that file that are not in the sendmail.mc file.
As with the sendmail.cf file you need to comment out (or delete) the same option. In the sendmail.mc file this looks like so:
DAEMON_OPTIONS(`Port=smtp,Addr=127.0.0.1, Name=MTA')
After commenting out the line it will now look like so:
dnl DAEMON_OPTIONS(`Port=smtp,Addr=127.0.0.1, Name=MTA')
You now need to compile this file into a new sendmail.cf file by issuing the following command:
m4 sendmail.mc > sendmail.cf
and then restarting sendmail. Remember it's important to make a backup copy of the sendmail.cf file first so you can revert back to it if sendmail stops working like it did before.
Related posts:
- Show the sendmail mail queue (Sunday, November 2nd 2008)
- Opening port 25 for mail servers with iptables (Sunday, November 30th 2003)
- Sendmail Connection Refused on localhost (Sunday, November 30th 2003)
Recent posts:
- MySQL queries for article summaries part 2 of 2 (Tuesday, January 6th 2009)
- Aims for 2009 (Monday, January 5th 2009)
- Weekly Roundup - January 5th 2008 (Monday, January 5th 2009)
- MySQL queries for article summaries part 1 of 2 (Sunday, January 4th 2009)
- 2008 Summary of Posts (Saturday, January 3rd 2009)
- 2008 / 2009 overview (Friday, January 2nd 2009)
Subscribe to RSS Feed / Email / Bookmark / Share
Use the buttons below to subscribe to my RSS feed to be notified next time something is posted, share this post with others, or subscribe by email and have my posts sent in a daily email.
Posts are made using the following schedule (although it may vary some weeks): Mondays & Fridays = PHP; Tuesdays & Saturdays = MySQL; Wednesdays & Sundays = Javascript/jQuery; Thursdays = HTML/CSS.
