#!/bin/bash #DESC Configures Sendgrid. Need API Key and email from add. ID=$(/usr/bin/id -u) [ $ID -ne 0 ] && echo "You must be root to run $0." && exit 1 #--Configure RTI Server for Sendgrid email relay. #a. Get API Key. echo -n "Enter API Key: " read APIKEY #b. Get Email From Address. echo -n "Enter Server Email From Address: " read EMAIL_FROM [ "$EMAIL_FROM" == "" ] && EMAIL_FROM="None" #c. Be Sure. echo "APIKEY: $APIKEY" echo "SERVER EMAIL ADDRESS: $EMAIL_FROM" echo -n "Are these correct? (Y/N):" read REPLY [ "$REPLY" != "Y" ] && exit 1 #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 #2. Create mail auth folder. rm -rf /etc/mail/auth mkdir /etc/mail/auth chmod 777 /etc/mail/auth #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 echo "define(\`SMART_HOST',\`smtp.sendgrid.net')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 #6. Create authentication file and build authentication db. echo "AuthInfo:smtp.sendgrid.net \"U:apikey\" \"P:$APIKEY\" \"M:PLAIN\"">/etc/mail/auth/authinfo makemap hash /etc/mail/auth/authinfo < /etc/mail/auth/authinfo #7. Set permissions on authentication files. chmod 600 /etc/mail/auth/authinfo chmod 700 /etc/mail/auth #8. Restart sendmail. service sendmail restart #9. Test email. echo "Done."