1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- #!/bin/bash
- ################################################################
- # Prerequisites
- ################################################################
- # Ensure we are up-to-date and have required software installed
- yum update -y
- yum install postfix python-virtualenv -y
- # Create user for handling mail
- useradd -m -s /sbin/nologin incoming
- ################################################################
- # Setup postfix
- ################################################################
- # Remove defaults that may interfere
- sed -i -e 's/^\s*\(inet_interfaces\s*=\)/#\1/' \
- -e 's/^\s*\(mydestination\s*=\)/#\1/' \
- -e 's/^\s*\(mynetworks\s*=\)/#\1/' \
- -e 's/^\s*\(home_mailbox\s*=\)/#\1/' \
- -e 's/^\s*\(alias_maps\s*=\)/#\1/' \
- /etc/postfix/main.cf
- # Configure postfix
- cat <<EOF >> /etc/postfix/main.cf
- # HOSTING CONFIG FOR EMAIL PARSING
- inet_interfaces = all
- mynetworks = 127.0.0.1/32
- virtual_alias_maps = regexp:/etc/postfix/virtual_aliases
- virtual_alias_domains = accounts.hosting.com
- home_mailbox = Maildir/
- EOF
- # Disable ALL bounces
- sed -i 's/^\(bounce\s.*\)bounce$/\1discard/' /etc/postfix/master.cf
- # Write aliases for users we want to handle mail for
- cat <<EOF > /etc/postfix/virtual_aliases
- /^[0-9]+-[0-9]+@accounts\.hosting\.com$/ incoming
- /^support@accounts\.hosting\.com$/ incoming
- EOF
- # Restart postfix
- systemctl restart postfix
- ################################################################
- # Setup mailparser environment
- ################################################################
- # Setup virtualenv from which we will run everything
- # (this helps prevent yum from breaking functionality)
- sudo -u incoming bash -c " \
- virtualenv ~incoming/venv \
- source ~incoming/venv/bin/activate \
- pip install mailbox requests \
- "
|