Configuring Postfix for Inbound Email - Phabricator

Local MTA: Configuring Postfix for Inbound Email – Phabricator

Whenever something is update on a software development platform, usually an email is sent to all subscribed users. Phabricator let you reply to those emails and perform a specific action like assign, claim, close, change priority and status, unsubscribe, etc. In order for this to function with a local MTA like Postfix, a manual setup must be done.

 

Before everything, read the official page on configuring inbound email to see how things work and what configuration must be made. I’ll go again through some setup already mentioned in the guide, just to mention the most important steps and some additional ones.

 

Configuring Phabricator

Navigate to Mail Configuration page and check if the following options are set:

metamta.domain: domain.com
metamta.default-address: noreply@phab.domain.com
metamta.reply-handler-domain: phab.domain.com
metamta.single-reply-handler-prefix: post

The metamta.single-reply-handler-prefix option is not mandatory, but this is what I have chosen for my setup because I have other email accounts on phab.domain.com. For more about this, check the link above.

 

Local MTA: Installing Mailparse

Install mailparse package as described in the guide (I managed to do it via pecl).

If you have individual files in /etc/php.d/, then search for a mbstring file (I had a 20-mbstring.ini file). All the configs in this directory are loaded alphabetically, so in order to have this package loaded after the mbstring, create a file with a name that will sort higher. For my setup, I’ve created a 21-mailparse.ini file and added the following content to it:

; Enable mailparse extension module
extension=mailparse.so

 

Local MTA: Configuring Postfix

Located at /home/dummy/phab.domain.com/public_html/phabricator/ the mail_handler.php script must be run by Postfix with a user that has permissions over it.

By default, Postfix runs everything with its own user, therefore if we add the user & script in the /etc/aliases (as described in the guide – Configuring Sendmail section) an error with occur when Postfix will try to run the mail_handler.php script, so we’re going to make some local aliases and then load them in the main configuration of Postfix.

 

For our phab.domain.com we’ll assume that the owner of the  mail_handler.php is dummy.

Now, change directory to /home/dummy/phab.domain.com/ and run the following:

[dummy@host ~]$ sudo ln -s /home/dummy/phab.domain.com/public_html/phabricator/scripts/mail/mail_handler.php /etc/smrsh/
[dummy@host ~]$ echo "dummy: |/home/dummy/phab.domain.com/public_html/phabricator/scripts/mail/mail_handler.php" >> .phabricator_inbound_aliases
[dummy@host ~]$ postalias .phabricator_inbound_aliases

The last two commands will create two files: .phabricator_inbound_aliases and  .phabricator_inbound_aliases.db. Both files must be owned by dummy.

 

Open /etc/postfix/main.cf in edit mode, search for alias_maps and alias_database and add the domain specific alias after the existing value, separating it via comma. In the end it should look like this:

alias_maps = hash:/etc/aliases, hash:/home/dummy/phab.domain.com/.phabricator_inbound_aliases
alias_database = hash:/etc/aliases, hash:/home/dummy/phab.domain.com/.phabricator_inbound_aliases

After making this change, run sudo newaliases.

 

Open /etc/postfix/virtual in edit mode and at the end add a new line:

@phab.domain.com     dummy@localhost

This will redirect all email that goes to the specified domain to the dummy alias, which will run the mail_handler.php script that will parse the email and execute given commands.

 

Restart Apache & Postfix and you’re all set.

4 Comments

  • Remus Avram

    October 19, 2017

    Hi Tanase,
    thanks for sharing this information.
    I am trying to set up inbound email for my Phabricator instance, and I found it (like they say) quite difficult.
    Looking at your post I see that you are not talking anything about configuring MX records. I don’t know how to configure this. Any hints?

    Reply
    • Tanase Butcaru

      October 20, 2017

      Hi Remus,

      I’m using Webmin/Virtualmin to manage my domains/hosting, so my MX records have been added automatically by the Virtualmin wizard.
      I did nothing special about them, I have the usual MX records a website has.

      If you’re building your server from scratch, without using a control panel (eg. Webmin/VirtualMin, VestaCP, etc), then you have to install & configure your local mail server (sendmail, postfix, etc).

      Tanase B.

      Reply
  • Remus

    October 19, 2017

    Hi Tanase,
    can you please share with us how you managed to install `mailparse` via `pecl`?
    I failed installing it via `pecl` but I installed `php-pecl-mailparse` rpm package. I am not sure if it’s the same…

    Reply
    • Tanase Butcaru

      October 20, 2017

      Hi Remus,

      I’ve installed pecl just by following the official guide on how to install mailparse.
      If you don’t have any PHP errors on startup after including mailparse.so, then I think you’re good with php-pecl-mailparse!

      Reply

Leave a Reply