Skip to content
This repository has been archived by the owner on Mar 27, 2022. It is now read-only.

Postfix Email Setup

Tim Morgan edited this page Mar 1, 2017 · 13 revisions

This page contains instructions for how to set up a Linux server with Postfix mail server software. By the end, you will have a single catch-all address for OneBody to use.

1. DNS MX Records

First, go to your domain registrar/DNS provider and add MX records for your domain name pointing to your server.

At minimum you'll need an MX record pointing to your domain name.

2. Install Postfix

  1. Install Postfix and Courier POP on your server:

    sudo apt-get install postfix courier-pop
    

    When prompted, choose "Internet Site" for the Postfix configuration.

    When prompted for the system name, enter the same domain you use to access OneBody, e.g. members.mychurch.com or whatever.

  2. Next, create a user:

    sudo adduser onebodymail
    

    (set the password to something you will remember)

  3. Edit your Postfix config file:

    Now edit /etc/postfix/main.cf to include the following (just add below any existing config, adjusting for your own domain):

    mydestination = members.mychurch.com, localhost.localdomain, localhost
    home_mailbox = Maildir/
    smtp_discard_ehlo_keywords=pipelining,discard
    message_size_limit = 25600000
    local_recipient_maps =
    luser_relay = onebodymail
    

    Make sure you change members.mychurch.com to your actual domain name you use to access OneBody.

    If that last line doesn't work, you may need to put onebodymail@members.mychurch.com instead of just onebodymail.

    The size limit is to give messages a limit of about 25MB. Increase or decrease to fit your own need.

  4. If the follow line is in there, be sure to remove it, or it won't work:

    mailbox_command = procmail -a "$EXTENSION"
    
  5. Reload postfix:

    sudo postfix reload
    

3. Testing Delivery

Now, send a message to test@members.mychurch.com. Now, let's check to see if the email arrived...

su -l onebodymail
(type the password you set before)
cd
ls Maildir/new

Check that something is there. A new file should appear in this directory every time you send a test message. If not, then something isn't configured right. Don't go past this step until you can verify emails are appearing in that directory.

4. Testing Login

  1. Get back to your regular login (not onebodymail):

    exit
    
  2. Edit your email config:

    cd /etc/onebody
    vim email.yml
    

    The config should look something like this:

    production:
      pop:
        host:      "localhost"
        username:  "onebodymail"
        password:  "PASSWORD_YOU_SET_EARLIER"
      smtp:
        address:   "localhost"
        domain:    "YOUR_DOMAIN"
        enable_starttls_auto: false
    
  3. Test that the script works:

    onebody run script/inbox -e production localhost onebodymail PASSWORD_YOU_SET_EARLIER
    

    This script should produce no output. If the test email was to a valid OneBody address and from a recognizable email (from a user within OneBody), then the message should disappear from the /home/onebodymail/Maildir/new directory.

    If you want to test actual mail delivery within the OneBody system, then:

    1. Ensure you're sending from an address OneBody knows about, like your personal email address (make sure your profile in OneBody has the email address, otherwise your message will be rejected as unknown sender).
    2. Create a test group with one person in it (you), and give it an email address.
    3. Send a test message to that email address.
    4. Run the "inbox" script to tell OneBody to grab the message (be sure to give it a little while to let the message arrive).

    If that works, you should:

    1. See the message when you view the group via the web.
    2. Get the email sent back to you as a member of the group.

    If all that worked, then there's only one more thing to do...

5. Automate with Crontab

onebody run whenever -w

This will set your user's crontab so that it runs script/inbox once a minute.

Additional information - emails sent by onebody may be treated as SPAM without a bit of extra work. To fix this:

  1. Ensure reverse dns is set up - with digital ocean just make sure your server name is the same as your dns name.
  2. Add an SPF record to your DNS record (TXT entry - there are tools that can be used to create this string).
  3. You may need to ask users to add noreply@yourdomain.com to address books/contacts.