Blogmark
Postfix Setup for Action Mailbox
via jbranchaud@gmail.com
This stackoverflow answer provides a ton of good detail how on to get Postfix setup with Rails' Action Mailbox.
I also wanted to document the steps I took with the added detail that this is for a Hatchbox and Hetzner configuration:
Find the email that Hatchbox sent ([Hatchbox] Your new server password) with the password for the
deployuser to be able to run commands asrootwithsudo. This is needed for a couple things.Hatchbox / Hetzner do not have
postfixinstalled, so it needs to be done manually.$ sudo apt-get update $ sudo apt-get install postfixCreate the virtual mailbox mapping file which tells Postfix what our catch-all email recipient will be —
sudo vi /etc/postfix/virtual.mydomain.tld anything @mydomain.tld catch-all@mydomain.tldThe first line tells Postfix that we accept email for our domain. The second line is the catch-all line which takes any mail that doesn't match a specific address and sends it to
catch-all@mydomain.tldassuming thecatch-alluser exists.Create the
catch-alluser.$ sudo useradd --create-home --shell /sbin/nologin catch-allAdd Postfix transport file which indicates the name of the thing that is going to forward emails to Rails —
sudo vi /etc/postfix/transport:mydomain.tld forward_to_rails:Compile
virtualandtransportinto Berkley DB files withpostmap. This can be done from whatever directory you're already in.$ sudo postmap /etc/postfix/virtual $ sudo postmap /etc/postfix/transportNotice in
ls /etc/postfixthat there is now avirtual.dbandtransport.dbfile.Add this email forwarding script (with the command mentioned in the Rails Action Mailbox docs for Postfix) to
/usr/local/binin a file likeemail_forwarder.sh:#!/bin/sh cd /home/deploy/visualmode-dev-rails-app/current && bin/rails action_mailbox:ingress:postfix URL='https://mydomain.tld/rails/action_mailbox/relay/inbound_emails' INGRESS_PASSWORD='ingress_password'Note that this command needs a
URLwhich is your fully-qualified URL followed by/rails/action_mailbox/relay/inbound_emails. It also needs theINGRESS_PASSWORDthat Rails will be configured with, such as with theRAILS_INBOUND_EMAIL_PASSWORDenv var.Then at the end of the
master.cffile, I added the following lines, ensuring not to modify anything else in there —sudo vi /etc/postfix/master.cf:forward_to_rails unix - n n - - pipe flags=Xhq user=deploy:deploy argv=/usr/local/bin/email_forwarder.sh ${nexthop} ${user}Since my user is already called
deploy, I can leave theuser=deploy:deployas is.Update the
main.cffile with mapping and transport files —sudo vi /etc/postfix/main.cf:transport_maps = hash:/etc/postfix/transport virtual_alias_maps = hash:/etc/postfix/virtualThen to make sure that Postfix is aware of all the latest changes, I reload it.
$ sudo postfix reload $ sudo systemctl reload postfix