setup.sh 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #!/bin/bash
  2. # Ensure we are up-to-date and have postfix installed
  3. yum update -y
  4. yum install postfix -y
  5. # Create user for handling mail
  6. useradd -m -s /sbin/nologin incoming
  7. # Remove defaults that may interfere
  8. sed -i -e 's/^\s*\(inet_interfaces\s*=\)/#\1/' \
  9. -e 's/^\s*\(mydestination\s*=\)/#\1/' \
  10. -e 's/^\s*\(mynetworks\s*=\)/#\1/' \
  11. -e 's/^\s*\(home_mailbox\s*=\)/#\1/' \
  12. -e 's/^\s*\(alias_maps\s*=\)/#\1/' \
  13. /etc/postfix/main.cf
  14. # Configure postfix
  15. cat <<EOF >> /etc/postfix/main.cf
  16. # HOSTING CONFIG FOR EMAIL PARSING
  17. inet_interfaces = all
  18. mynetworks = 127.0.0.1/32
  19. virtual_alias_maps = regexp:/etc/postfix/virtual_aliases
  20. virtual_alias_domains = accounts.hosting.com
  21. home_mailbox = Maildir/
  22. EOF
  23. # Disable ALL bounces
  24. sed -i 's/^\(.*\)bounce$/\1discard/' /etc/postfix/master.cf
  25. # Write aliases for users we want to handle mail for
  26. cat <<EOF > /etc/postfix/virtual_aliases
  27. /^[0-9]+-[0-9]+@accounts\.hosting\.com$/ incoming
  28. /^support@accounts\.hosting\.com$/ incoming
  29. EOF
  30. # Restart postfix
  31. systemctl restart postfix