setup.sh 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #!/bin/bash
  2. ################################################################
  3. # Prerequisites
  4. ################################################################
  5. # Ensure we are up-to-date and have required software installed
  6. yum update -y
  7. yum install postfix python-virtualenv -y
  8. # Create user for handling mail
  9. useradd -m -s /sbin/nologin incoming
  10. ################################################################
  11. # Setup postfix
  12. ################################################################
  13. # Remove defaults that may interfere
  14. sed -i -e 's/^\s*\(inet_interfaces\s*=\)/#\1/' \
  15. -e 's/^\s*\(mydestination\s*=\)/#\1/' \
  16. -e 's/^\s*\(mynetworks\s*=\)/#\1/' \
  17. -e 's/^\s*\(home_mailbox\s*=\)/#\1/' \
  18. -e 's/^\s*\(alias_maps\s*=\)/#\1/' \
  19. /etc/postfix/main.cf
  20. # Configure postfix
  21. cat <<EOF >> /etc/postfix/main.cf
  22. # HOSTING CONFIG FOR EMAIL PARSING
  23. inet_interfaces = all
  24. mynetworks = 127.0.0.1/32
  25. virtual_alias_maps = regexp:/etc/postfix/virtual_aliases
  26. virtual_alias_domains = accounts.hosting.com
  27. home_mailbox = Maildir/
  28. EOF
  29. # Disable ALL bounces
  30. sed -i 's/^\(bounce\s.*\)bounce$/\1discard/' /etc/postfix/master.cf
  31. # Write aliases for users we want to handle mail for
  32. cat <<EOF > /etc/postfix/virtual_aliases
  33. /^[0-9]+-[0-9]+@accounts\.hosting\.com$/ incoming
  34. /^support@accounts\.hosting\.com$/ incoming
  35. EOF
  36. # Restart postfix
  37. systemctl restart postfix
  38. ################################################################
  39. # Setup mailparser environment
  40. ################################################################
  41. # Setup virtualenv from which we will run everything
  42. # (this helps prevent yum from breaking functionality)
  43. sudo -u incoming bash -c " \
  44. virtualenv ~incoming/venv \
  45. source ~incoming/venv/bin/activate \
  46. pip install mailbox requests \
  47. "