Skip to content

Instantly share code, notes, and snippets.

@timstermatic
Forked from dhensby/sendmail-fix.sh
Created February 16, 2017 19:24
Show Gist options
  • Save timstermatic/d98b2f5a7d1263019a77b0dfd17d2b3c to your computer and use it in GitHub Desktop.
Save timstermatic/d98b2f5a7d1263019a77b0dfd17d2b3c to your computer and use it in GitHub Desktop.
Stop sendmail delivering to localhost when email domain matches hostname, stop sendmail intercepting emails to info@ and others - CentOS, RHEL, Fedora
#!/bin/bash
##
##
## This scipt was inspired by http://serverfault.com/questions/65365/disable-local-delivery-in-sendmail/128450#128450
## It stops webservers sending mail that is addressed to the local hostname to localhost and instead looks remotely for a mail server
##
##
# Install sendmail-cf as this is required to customise the config
yum install -y sendmail-cf
# Add a couple of lines to the end of the sendmail.mc config file
echo "define(\`MAIL_HUB', \``hostname`.')dnl" >> /etc/mail/sendmail.mc
echo "define(\`LOCAL_RELAY', \``hostname`.')dnl" >> /etc/mail/sendmail.mc
# Fixes an issue where certain email addresses are intercepted by the server
sed '/info:/d' /etc/aliases | sed '/sales:/d' | sed '/support:/d' | sed '/marketing:/d' | sed '/news/d' | sed '/games:/d' | sed '/abuse:/d' | sed '/mail:/d' | sed '/fax:/d' > /etc/newaliases && mv /etc/aliases /etc/aliases.old && mv /etc/newaliases /etc/aliases
# Make the config
/etc/mail/make
# Restart the service
service sendmail restart
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment