#!/bin/bash ID=$(/usr/bin/id -u) [ $ID -ne 0 ] && echo "You must be root to run $0." && exit 1 #DESC Build generics table for sendmail to prevent .teleflora.com from getting added tosystem email from addresses. tar cvfz /tmp/mail.tar.gz /etc/mail [ "`grep ^DS /etc/mail/sendmail.cf | cut -dS -f2`" != "" ] && echo "Relay already configured." && exit 1 [ -d /etc/mail/auth ] && echo "Sendgrid configured on this server. Exiting in success." && exit 0 locate sendmail >>/dev/null [ "$?" != "0" ] && echo "sendmail not found!" && exit 1 [ -f /etc/mail/genericstable ] && mv /etc/mail/genericstable /tmp/genericstable.bak EMAIL_FROM="posserver@`hostname | cut -d. -f1`.com" #1. Remove postfix if there and install and enable sendmail instead. (Good for RH6 and RH7.) yum repolist [ "$?" != "0" ] && echo "Server needs to be registered with Redhat." && exit 1 yum -y remove postfix yum -y install sendmail sendmail-cf [ "$?" != "0" ] && echo "Unable to install the required packages." && exit 1 chkconfig sendmail on #3. Backup config files just in case. cp -f /etc/mail/sendmail.mc /tmp/sendmail.mc.`date +"%m%d%H%M%S"` cp -f /etc/mail/sendmail.cf /tmp/sendmail.cf.`date +"%m%d%H%M%S"` #4. Create generics table. if [ "$EMAIL_FROM" != "None" ]; then echo "root $EMAIL_FROM">>/etc/mail/genericstable echo "root@localhost $EMAIL_FROM">>/etc/mail/genericstable echo "root@`hostname` $EMAIL_FROM">>/etc/mail/genericstable echo "root@`hostname`.teleflora.com $EMAIL_FROM">>/etc/mail/genericstable echo "rti $EMAIL_FROM">>/etc/mail/genericstable echo "rti@localhost $EMAIL_FROM">>/etc/mail/genericstable echo "rti@`hostname` $EMAIL_FROM">>/etc/mail/genericstable echo "rti@`hostname`.teleflora.com $EMAIL_FROM">>/etc/mail/genericstable echo "tfsupport $EMAIL_FROM">>/etc/mail/genericstable echo "tfsupport@localhost $EMAIL_FROM">>/etc/mail/genericstable echo "tfsupport@`hostname` $EMAIL_FROM">>/etc/mail/genericstable echo "tfsupport@`hostname`.teleflora.com $EMAIL_FROM">>/etc/mail/genericstable fi #5. Make changes to sendmail.mc and build new sendmail.cf. cp -f /etc/mail/sendmail.mc /etc/mail/sendmail.mc.new sed -i '/^MAILER/d' /etc/mail/sendmail.mc.new sed -i '/MAILER(cyrusv2)/d' /etc/mail/sendmail.mc.new echo "FEATURE(authinfo,\`hash /etc/mail/auth/authinfo')dnl">>/etc/mail/sendmail.mc.new echo "FEATURE(\`genericstable')dnl">>/etc/mail/sendmail.mc.new echo "GENERICS_DOMAIN(\`localhost')dnl">>/etc/mail/sendmail.mc.new echo "GENERICS_DOMAIN(\``hostname`')dnl">>/etc/mail/sendmail.mc.new echo "GENERICS_DOMAIN(\``hostname`.teleflora.com')dnl">>/etc/mail/sendmail.mc.new echo "MAILER(smtp)dnl">>/etc/mail/sendmail.mc.new echo "MAILER(procmail)dnl">>/etc/mail/sendmail.mc.new m4 /etc/mail/sendmail.mc.new > /etc/mail/sendmail.cf mv -f /etc/mail/sendmail.mc.new /etc/mail/sendmail.mc #8. Restart sendmail. service sendmail restart #9. Test email. echo "Done."