<p>I'm setting up a server which is on a network behind a firewall and I want programs on this computer to be able to use sendmail to send emails to any email address.  We have an SMTP server running on this network (let's call it mailrelay.example.com) which is how we're supposed to get outgoing emails through the firewall.</p>

<p>So how do I configure sendmail to send all mail through mailrelay.example.com?  Googling hasn't given me the answer yet, and has only revealed that sendmail configuration is extremely complex and annoying.</p>

[{'answer_id': 43977, 'author': 'Espo', 'author_id': 2257, 'author_profile': 'https://Stackoverflow.com/users/2257', 'pm_score': 3, 'selected': False, 'text': '<p><a href="http://www.elandsys.com/resources/sendmail/smarthost.html" rel="noreferrer">http://www.elandsys.com/resources/sendmail/smarthost.html</a></p>\n\n<blockquote>\n  <p>Sendmail Smarthost</p>\n  \n  <p>A smarthost is a host through which\n  outgoing mail is relayed. Some ISPs\n  block outgoing SMTP traffic (port 25)\n  and require their users to send out\n  all mail through the ISP\'s mail\n  server. Sendmail can be configured to\n  use the ISP\'s mail server as the smart\n  host.</p>\n</blockquote>\n\n<p>Read the linked article for instruction for how to set this up.</p>\n'}, {'answer_id': 44014, 'author': 'Eli Courtwright', 'author_id': 1694, 'author_profile': 'https://Stackoverflow.com/users/1694', 'pm_score': 2, 'selected': False, 'text': '<p>@Espo: Thanks for the great advice on where to start.  Your link would have been better if I had been configuring sendmail for its first use instead of taking an existing configuration and making this small change.  However, once I knew to look for stuff on "SmartHost", I found an easier way.</p>\n\n<p>All I had to do was edit my /etc/mail/sendmail.cf file to change</p>\n\n<pre><code>DS\n</code></pre>\n\n<p>to</p>\n\n<pre><code>DSmailrelay.example.com\n</code></pre>\n\n<p>then restart sendmail and it worked.</p>\n'}, {'answer_id': 107795, 'author': 'tardate', 'author_id': 6329, 'author_profile': 'https://Stackoverflow.com/users/6329', 'pm_score': 5, 'selected': True, 'text': '<p>@eli: modifying sendmail.cf directly is not usually recommended, since it is generated by the macro compiler. </p>\n\n<p>Edit /etc/mail/sendmail.mc to include the line:</p>\n\n<pre><code>  define(`SMART_HOST\',`mailrelay.example.com\')dnl \n</code></pre>\n\n<p>After changing the sendmail.mc macro configuration file, it must be recompiled\nto produce the sendmail configuration file.</p>\n\n<pre><code>  # m4 /etc/mail/sendmail.mc &gt; /etc/sendmail.cf\n</code></pre>\n\n<p>And restart the sendmail service (Linux):</p>\n\n<pre><code>  # /etc/init.d/sendmail restart\n</code></pre>\n\n<p>As well as setting the smarthost, you might want to also disable name resolution configuration and possibly shift your sendmail to non-standard port, or disable daemon mode.</p>\n\n<h1>Disable Name Resolution</h1>\n\n<p>Servers that are within fire-walled networks or using Network Address\nTranslation (NAT) may not have DNS or NIS services available. This creates\na problem for sendmail, since it will use DNS by default, and if it is not\navailable you will see messages like this in mailq:</p>\n\n<pre><code>  host map: lookup (mydomain.com): deferred)\n</code></pre>\n\n<p>Unless you are prepared to setup an appropriate DNS or NIS service that\nsendmail can use, in this situation you will typically configure name\nresolution to be done using the /etc/hosts file. This is done by enabling\na \'service.switch\' file and specifying resolution by file, as follows:</p>\n\n<p>1: Enable service.switch for sendmail\nEdit /etc/mail/sendmail.mc to include the lines:</p>\n\n<pre><code>  define(`confSERVICE_SWITCH_FILE\',`/etc/mail/service.switch\')dnl\n</code></pre>\n\n<p>2: Configure service.switch for files\nCreate or modify /etc/mail/service.switch to refer only to /etc/hosts for name\nresolution:</p>\n\n<pre><code>  # cat /etc/mail/service.switch\n  hosts files\n</code></pre>\n\n<p>3: Recompile sendmail.mc and restart sendmail for this setting to take effect.</p>\n\n<h1>Shift sendmail to non-standard port, or disable daemon mode</h1>\n\n<p>By default, sendmail will listen on port 25. You may want to change this port\nor disable the sendmail daemon mode altogether for various reasons:\n- if there is a security policy prohibiting the use of well-known ports\n- if another SMTP product/process is to be running on the same host on the standard port\n- if you don\'t want to accept mail via smtp at all, just send it using sendmail</p>\n\n<p>1: To shift sendmail to use non-standard port.\nEdit /etc/mail/sendmail.mc and modify the "Port" setting in the line:</p>\n\n<pre><code>  DAEMON_OPTIONS(`Port=smtp,Addr=127.0.0.1, Name=MTA\')\n</code></pre>\n\n<p>For example, to get sendmail to use port 125:</p>\n\n<pre><code>  DAEMON_OPTIONS(`Port=125,Addr=127.0.0.1, Name=MTA\')\n</code></pre>\n\n<p>This will require sendmail.mc to be recompiled and sendmail to be restarted.</p>\n\n<p>2: Alternatively, to disable sendmail daemon mode altogether (Linux)\nEdit /etc/sysconfig/sendmail and modify the "DAEMON" setting to:</p>\n\n<pre><code>  DAEMON=no\n</code></pre>\n\n<p>This change will require sendmail to be restarted.</p>\n'}]
['https://Stackoverflow.com/questions/43970', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/1694/']