How to config sendmail to send mail in Linux
It will describe how to config sendmail to send mail to XX smtp server.
Test Env:
$ uname -a Linux smcfrd64 2.6.18-128.el5 #1 SMP Wed Dec 17 11:42:39 EST 2008 i686 i686 i386 GNU/Linux
Linux computer IP: 16.186.77.7
pre-condition: DNS is set up. Package sendmail and sendmail-cf should be installed.
1. Config the host name of the linux server
Check the file /etc/hosts, make sure that the loopback IP 127.0.0.1 is configed in the first line and the NIC IP is configed with the format [IP shortname FQDN name with domain]. If no, please add them manually.The FQDN name with domain is necessary for sendmail. Refer to the valid file content as follow.
127.0.0.1 localhost.localdomain localhost
::1 localhost6.localdomain6 localhost6
16.157.128.106 ux14231
16.157.128.127 ux14229
16.186.77.7 smcfrd64 smcfrd64.localdomain.com'
You can try the command below to check whether the hostname is configed correctly.
$host smcfrd64.localdomain.com
2. Check whether sendmail service is started
$ sudo service sendmail status
if it is running, then stop it.
$ sudo service sendmail stop
3. Config sendmail
1) Edit the file /etc/mail/sendmail.mc
Uncomment the definition SMART_HOST and add the correspondign FEATURE to it:
define(`SMART_HOST', `[smtp.xx.com.]')dnl
FEATURE(`authinfo',`hash /etc/mail/authinfo.db')dnl
2) Run m4 command to generate new sendmail.cf
$m4 /etc/mail/sendmail.mc > /etc/mail/sendmail.cf
If you don't log on as root, you will fail to run this command even using sudo. You can run it in an alternative way.
$sudo m4 /etc/mail/sendmail.mc > /tmp/sendmail.cf
$sudo cp /tmp/sendmail.cf .
3) Edit/create the file /etc/mail/authinfo, add the follow line, containing your smtp server, mail account and password:
AuthInfo:smtp.xx.com "U:domain.com@noip-smtp" "P:*******"
4) Map the authinfo file
$makemap hash /etc/mail/authinfo < /etc/mail/authinfo
4. Start the sendmail service. You can read the file in /var/log/maillog to see whether thesendmail starts successfully. You can also run the command below to test it:
$echo "test van Brunöö, this is één mail"|mail -s "test éne mail" XXX@hp.com