-
Notifications
You must be signed in to change notification settings - Fork 283
Mailgun Email Setup
Following are instructions for setting up a Mailgun account for incoming and outgoing email with OneBody. Mailgun offers a free tier for up to 10,000 email messages per month.
For the instructions below, we're going to assume your OneBody domain is members.mychurch.com. Just replace that with your own domain everywhere below.
In the Mailgun web interface:
-
Create a domain. Make sure it matches exactly the domain you use for your OneBody website, e.g. if your OneBody site is members.mychurch.com, then your Mailgun email domain should also be members.mychurch.com. If you want to live dangerously, you can set it differently, but you'll need to set your OneBody email_host to match.
-
After creating a domain in Mailgun go through the steps that mailgun provides in order to Add Sending & Tracking DNS Records. You can add all three types (TXT, CNAME, MX). Here are some instructions for setting up DNS on DigitalOcean.
-
Create a priority 0 "catchall" route in Mailgun (this is in the routes section of Mailgun) that forwards to
http://members.mychurch.com/emails.mime
. The final route should look like this:0 catch_all() forward("http://members.mychurch.com/emails.mime")
-
Under the "Domain information" section, take note of your SMTP Login and Password information.
On your OneBody server:
-
Create a copy of the mailgun example file (note: if you installed OneBody from a debian package this file already exists at
/etc/onebody/email.yml
and you can skip this step):cp config/email.yml{.mailgun-example,}
-
Edit your
email.yml
config file to look like this (replaceYOUR_SMTP_USERNAME
andYOUR_SMTP_PASSWORD
below with the details you got in step 3 above; also remember to change the "members.mychurch.com" to your own domain name):production: smtp: address: "smtp.mailgun.org" domain: "members.mychurch.com" port: 587 user_name: "YOUR_SMTP_USERNAME" password: "YOUR_SMTP_PASSWORD" authentication: plain
-
Restart your server.
-
If you installed via the Debian package, run
service onebody restart
. -
If you installed manually (or if that command doesn't work), run
cd /var/www/onebody && touch tmp/restart.txt
.
-
-
Send email both ways (an incoming message from an outside address to a OneBody Group address; and an outgoing message from the website) to test that everything is working.
-
For some new accounts, DigitalOcean is blocking SMTP ports. File a support ticket to get them to lift that block.
-
Use the Mailgun "Logs" tab to see if there are any error messages.
-
Ensure your
email.yml
config file is formatted properly. Indentation should use two spaces (no tabs). -
Make sure to restart your server for the changes to take effect.
-
I just can't get it to work!
Try this in a terminal on your server:
⚡ gem install pony ⚡ irb -r pony irb(main):001:0> Pony.mail(to: 'YOUR_EMAIL', from: 'YOUR_EMAIL', subject: 'test', body: 'hello', via: :smtp, via_options: { address: 'smtp.mailgun.org', port: 587, user_name: 'MG_USER_NAME', password: 'MG_PASSWORD', domain: 'members.factoledo.org', authentication: :plain }) => #<Mail::Message:20807040>
If the email is sent, then something is probably wrong with your
email.yml
config. Check that.If the email fails, check your user name, password, and sending domain.