@eli: modifying sendmail.cf directly is not usually recommended, since it is generated by the macro compiler.
Edit /etc/mail/sendmail.mc to include the line:
define(`SMART_HOST',`mailrelay.example.com')dnl
After changing the sendmail.mc macro configuration file, it must be recompiled
to produce the sendmail configuration file.
# m4 /etc/mail/sendmail.mc > /etc/sendmail.cf
And restart the sendmail service (Linux):
# /etc/init.d/sendmail restart
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.
Disable Name Resolution
Servers that are within fire-walled networks or using Network Address
Translation (NAT) may not have DNS or NIS services available. This creates
a problem for sendmail, since it will use DNS by default, and if it is not
available you will see messages like this in mailq:
host map: lookup (mydomain.com): deferred)
Unless you are prepared to setup an appropriate DNS or NIS service that
sendmail can use, in this situation you will typically configure name
resolution to be done using the /etc/hosts file. This is done by enabling
a 'service.switch' file and specifying resolution by file, as follows:
1: Enable service.switch for sendmail
Edit /etc/mail/sendmail.mc to include the lines:
define(`confSERVICE_SWITCH_FILE',`/etc/mail/service.switch')dnl
2: Configure service.switch for files
Create or modify /etc/mail/service.switch to refer only to /etc/hosts for name
resolution:
# cat /etc/mail/service.switch
hosts files
3: Recompile sendmail.mc and restart sendmail for this setting to take effect.
Shift sendmail to non-standard port, or disable daemon mode
By default, sendmail will listen on port 25. You may want to change this port
or disable the sendmail daemon mode altogether for various reasons:
- if there is a security policy prohibiting the use of well-known ports
- if another SMTP product/process is to be running on the same host on the standard port
- if you don't want to accept mail via smtp at all, just send it using sendmail
1: To shift sendmail to use non-standard port.
Edit /etc/mail/sendmail.mc and modify the "Port" setting in the line:
DAEMON_OPTIONS(`Port=smtp,Addr=127.0.0.1, Name=MTA')
For example, to get sendmail to use port 125:
DAEMON_OPTIONS(`Port=125,Addr=127.0.0.1, Name=MTA')
This will require sendmail.mc to be recompiled and sendmail to be restarted.
2: Alternatively, to disable sendmail daemon mode altogether (Linux)
Edit /etc/sysconfig/sendmail and modify the "DAEMON" setting to:
DAEMON=no
This change will require sendmail to be restarted.