Mailgun

Setup mailgun for email sending

  1. Set up Mailgun account
  2. Verify and setup payment info
  3. Send -> Sending -> Domains -> Add new domain
  4. Pick a subdomain value for the purpose of this email sender
    • mg.yoursite.com booking.yoursite.com etc
    • We'll use booking for these instructions

Advanced settings (DKIM) -> 2048

  1. Click Add Domain

  2. Open up domain registrar (namecheap, etc.)

    • Domain List -> MANAGE -> Advanced DNS
  3. Add 3 DNS HOST records

    1. Under HOST RECORDS, click ADD NEW RECORD

    2. Click the A Record dropdown and select TXT Record

    3. For Host write in your subdomain i.e. booking

    4. For Value, paste in subdomain i.e. booking Note: The above step should cover this if you write in the Host manually. With Namecheap for the suggested Host value from Mailgun, we need to remove the tail end .yourdomain, leaving just the first part with the subdomain.

    5. Repeat above steps to add one more TXT Record where the Host is just your subdomain i.e. booking

    6. For Value, paste in the value from Mailgun

    moved this above * optional step here for better DKIM security: Click Regenerate DKIM, select 2048, add, and copy that new Value to paste in

    1. Add one more record in this section and select CNAME Record
    2. For Host write in email.subdomain i.e. email.booking
    3. Click SAVE ALL CHANGES
  4. Add 2 MAIL SETTINGS records

    1. Next to MAIL SETTINGS click the dropdown where the default is Email Forwarding and select Custom MX, or if it's already been set up before you can click ADD NEW RECORD
    2. For Host, write in your subdomain i.e. booking, removing the .yourdomain like above
    3. For Value, paste/write in mxa.mailgun.org.
    4. For Priority write in 10
    5. Click SAVE ALL CHANGES and add one more new MX Record by clicking ADD NEW RECORD, nearly identical to the other
    6. For Host, write in the same subdomain value
    7. For Value, paste/write in mxb.mailgun.org. (different)
    8. For Priority, write in the the same 10
    9. Click SAVE ALL CHANGES
  5. Go back to Mailgun and click Verify Records(?), and if successful it will clear the page. Note: If not successful immediately it may take 5+ minutes for the DNS records to propagate. If not resolved after 5m, go back to Namecheap and for the 5 new records, change the TTL dropdown from Automatic to 5 min, click SAVE ALL CHANGES for both sections. Then try to verify records after another 5m Congrats, you've connected Mailgun to send from your domain. You can use Mailgun via SMTP (email credentials) or an API key, depending on your application. Follow Mailgun Docs on this or follow the next instructions.

Mailgun SMTP Records

  1. Click Send -> Sending -> Domain settings
  2. Click the tab for SMTP credentials
  3. Click Add new SMTP user
  4. Under Login, write in a name for the email account
    • i.e. for the "booking" example, could do cal to get cal@booking.yoursite.com
  5. Leave Password creation set to Automatic
  6. Click Create
  7. Click Copy on the bottom-right pop-up
  8. Paste this in a password manager or somewhere safe with the full email above as the username
  9. Save these values in the same location, you will need later * HOST is smtp.mailgun.org * PORT we'll use 587 (Alt. 25, or 465)

These 4 values are needed for any application to send emails via SMTP protocol.

Mailgun Setup Forwarding Address

Since the credentials we created are only for outbound sending, we need to configure a forwarding address where any reply emails will be sent.

  1. Click Send -> Receiving
  2. Click Create Route
  3. Change the Expression Type dropdown to Match Recipient
  4. Under Recipient, fill in the user from the SMTP setup name@sub.website.com
  5. Toggle on Forward and fill in your email address you can receive mail at
  6. Optionally, add a Description
  7. Click Create route to save the forwarding settings