Skip to content

Instantly share code, notes, and snippets.

@cullylarson
Last active March 14, 2017 11:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save cullylarson/00f83e524088169176812b3915ba7ffc to your computer and use it in GitHub Desktop.
Save cullylarson/00f83e524088169176812b3915ba7ffc to your computer and use it in GitHub Desktop.
Catch all emails sent on a dev box and deliver them to the 'vagrant' user's mailbox
#
# Many apps send email. In a dev environment, we generally don't want those emails
# to get out. However, we still want our app to think it's sending mail and we want
# to verify that emails are being sent, with the correct content and to the correct
# recipients.
#
# This setup solves that problem by delivering all out-bound emails to the local
# "vagrant" user's mailbox. You can then read the emails using the "mutt" command.
#
# Most if this is copied from:
# http://www.intracto.com/nl/blog/dealing-e-mail-development-environment
# http://www.elho.net/mutt/maildir/
#
echo "\n--- Apt Update\n"
apt-get update
echo "\n--- Pre-Configuring Postfix\n"
echo "postfix postfix/mailname string vagrant" | debconf-set-selections
echo "postfix postfix/main_mailer_type string 'Internet Site'" | debconf-set-selections
echo "\n--- Installing Packages\n"
apt-get install -y postfix postfix-pcre mutt
# Postfix (Catches all outgoing email, puts it in the 'vagrant' user's mailbox. Use mutt to read it.)
echo "\n--- Configuring Postfix\n"
echo "" >> /etc/postfix/main.cf
echo "virtual_alias_domains =" >> /etc/postfix/main.cf
echo "virtual_alias_maps = pcre:/etc/postfix/virtual_forwardings.pcre" >> /etc/postfix/main.cf
echo "virtual_mailbox_domains = pcre:/etc/postfix/virtual_domains.pcre" >> /etc/postfix/main.cf
echo "home_mailbox = Maildir/" >> /etc/postfix/main.cf
echo "/@.*/ vagrant" > /etc/postfix/virtual_forwardings.pcre
echo "/^.*/ OK" > /etc/postfix/virtual_domains.pcre
# Mutt (for reading email)
echo "\n--- Configuring Mutt\n"
echo "" >> /etc/Muttrc
echo "set mbox_type=Maildir" >> /etc/Muttrc
echo "set folder=\"~/Maildir\"" >> /etc/Muttrc
echo "set mask=\"!^\\.[^.]\"" >> /etc/Muttrc
echo "set mbox=\"~/Maildir\"" >> /etc/Muttrc
echo "set record=\"+.Sent\"" >> /etc/Muttrc
echo "set postponed=\"+.Drafts\"" >> /etc/Muttrc
echo "set spoolfile=\"~/Maildir\"" >> /etc/Muttrc
echo "mailboxes \`echo -n \"+ \"; find ~/Maildir -maxdepth 1 -type d -name \".*\" -printf \"+'%f' \"\`" >> /etc/Muttrc
echo "macro index c \"<change-folder>?<toggle-mailboxes>\" \"open a different folder\"" >> /etc/Muttrc
echo "macro pager c \"<change-folder>?<toggle-mailboxes>\" \"open a different folder\"" >> /etc/Muttrc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment