Skip to content

Instantly share code, notes, and snippets.

@dhensby
Last active July 12, 2023 12:17
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save dhensby/8458203 to your computer and use it in GitHub Desktop.
Save dhensby/8458203 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
@davebuilt
Copy link

To stop the servers redirecting valid email addresses like "info@" to "root@" add the following before line 21:

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

@dhensby
Copy link
Author

dhensby commented Feb 10, 2014

thanks @Sixfifty

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment