This is the second part of a 2 series tutorial to setup action mailbox with postfix. In this part, we will configure postfix in production server to forward incoming emails to our rails app so action mailbox can process it.
If you haven't read the first part where we setup action mailbox and test it in development, you can read it here

You should have

Steps

Login to your production server first and then;
Step 1: Create bash script
Create a script inside
/usr/local/bin/
to forward all incoming emails to our rails app
shell
$ nano email_forwarder.sh
Add following to the script
shell
#!/bin/sh
export HOME=YOUR_HOME_PATH
export PATH=YOUR_PATH
export RBENV_ROOT=YOUR_RBENV_PATH

cd /path/to/your/project && bin/rails action_mailbox:ingress:postfix URL='https://truemark.com.np/rails/action_mailbox/relay/inbound_emails' INGRESS_PASSWORD='YOUR_INGRESS_PASSWORD'
Replace value of
HOME
,
PATH
,
RBENV_ROOT
,
URL
and
INGRESS_PASSWORD 
as described below:
cd
and copy what you get from
pwd
command
shell
$ cd
$ pwd
For
URL
, if your application lived at
https://example.com
, the full command would look like this:
bin/rails action_mailbox:ingress:postfix URL=https://example.com/rails/action_mailbox/relay/inbound_emails INGRESS_PASSWORD=YOUR_STRONG_PASSWORD
Step 2: Configure Postfix to Pipe Incoming emails to script
We will follow steps as described here.
Create
/etc/postfix/virtual_aliases
to add a catch-all alias; localuser needs to be an existing local user:
file
# /etc/postfix/virtual_aliases
@mydomain.tld   localuser@mydomain.tld
We should specify user so script is run by that user and not postfix or nobody.
user=deploy:deploy` ~ `user=user:group
You can view postfix log with
tail -f /var/log/mail.log
You must have everything now to receive email in your rails app. Test it with any of your email provider; just send the email to
[email protected]
and check if it is being received in the log. If you have any comments or suggestions, please let me know in comments below.
References