SendMail Configuration
Contents
Overview
Configuring sendmail MTA has a huge literature, only small tips will be described here.
The basis is the simple default configuration file on CentOS. See /etc/mail/sendmail.mc.orig. The goal of the changes to relay all outgoing emails from my CentOS workstations to my ISP and masquerade the domain and even the real linux user name to my email address at the ISP. See the complete configuration file /etc/mail/sendmail.mc.
Relay All Outgoing Mail to the ISP with Authentication
The following changes were performed in /etc/mail/sendmail.mc:
[root@centos1 mail]# diff sendmail.mc sendmail.mc.orig 26c26 < define(`SMART_HOST', `mail.hu.inter.net')dnl --- > dnl define(`SMART_HOST', `smtp.your.provider')dnl 78d77 < FEATURE(`authinfo',`hash -o /etc/mail/authinfo.db')dnl
where mail.hu.inter.net is the SMTP server of my ISP. The /etc/mail/authinfo.db is created from the /etc/mail/authinfo file:
[root@centos1 mail]# cd /etc/mail [root@centos1 mail]# vi authinfo # Add the following line (AuthInfo:ISP SMTP server "U:SMTP user" "P:SMTP password" "M:method"): AuthInfo:mail.hu.inter.net "U:nagyt@hu.inter.net" "P:Password to the SMTP server" "M:PLAIN" [root@centos1 mail]# chmod 640 authinfo [root@centos1 mail]# makemap hash /etc/mail/authinfo < /etc/mail/authinfo
Start service saslauthd as root to allow sendmail to use authentication.
chkconfig saslauthd on chkconfig --list saslauthd service saslauthd start
Masquerading User and Domain Name
Masquerading User and Domain Name is necessary to have real domain name, an email address in sender address. E.g: root@centos1.tibi1959.hu will be converted to nagyt@hu.inter.net. The following changes were performed in /etc/mail/sendmail.mc:
[root@centos1 mail]# diff sendmail.mc sendmail.mc.orig < dnl # Use generics table for masquerading < dnl # < FEATURE(genericstable, hash /etc/mail/generics)dnl < GENERICS_DOMAIN(centos1.tibi1959.hu)dnl < dnl # 166c160 < MASQUERADE_AS(`hu.inter.net')dnl --- > dnl MASQUERADE_AS(`mydomain.com')dnl 170c164 < FEATURE(masquerade_envelope)dnl --- > dnl FEATURE(masquerade_envelope)dnl
where hu.inter.net is the domain name of my ISP, centos1.tibi1959.hu is my internal domain name. The /etc/mail/generics.db is created from the file /etc/mail/generics:
[root@centos1 mail]# cd /etc/mail [root@centos1 mail]# vi generics # Add the following lines ("User name" "Full email address"), to allow root, ntibor and apache to send emails: root nagyt@hu.inter.net ntibor nagyt@hu.inter.net apache nagyt@hu.inter.net [root@centos1 mail]# chmod 640 generics [root@centos1 mail]# makemap hash /etc/mail/generics < /etc/mail/generics
Restarting sendmail
After all configurations are done, recreate /etc/mail/sendmail.cf and restart sendmail:
[root@centos1 mail]# cd /etc/mail [root@centos1 mail]# make all -C /etc/mail [root@centos1 mail]# /etc/init.d/sendmail restart