- Customer Success
How Do Users on G2 Rate Mailgun?
This post was written by Huey Ly. Huey is a software developer living and working in Xi’an China, home of the Terracotta warriors. He is the co-founder & lead developer for whyyu.com, a language learning app to teach English to Chinese children. In his spare time, he helps charitable organizations take advantage of technology to further their mission. He’s also a very brave dancer.
I volunteer part time at the Agape Community Care Association (www.agape.org), an NGO that helps orphans and other disadvantaged people in the Shaanxi province of China. Agape has volunteers and staff from all over the world, and most of their email accounts are hosted at free providers such as Gmail, Hotmail, or Yahoo. Agape wanted each volunteer to have their own @agape.org.cn email address to give the organization more legitimacy locally and internationally, but migrating and consolidating all the mailboxes of such a diverse group proved to be quite a headache. Additionally, the added cost of all the extra mailboxes would put a dent in their already minuscule funding (they only keep 10% of donations for administrative purposes, the rest goes directly to the orphanages and health clinics). What can they do?
Learn about our Deliverability Services
Looking to send a high volume of emails? Our email experts can supercharge your email performance. See how we've helped companies like Lyft, Shopify, Github increase their email delivery rates to an average of 97%.
Routes allow you to set up a series of rules on how to handle incoming messages, like those sent to @agape.org.cn . Specifically:
Which messages to act on (e.g. messages from a particular person or with a particular subject or even all messages)
What you want to do with those messages (e.g. forward it to another email address or POST it to your app)
For Agape, I wanted to match on anything sent to a user with an @agape.org.cn address and forward the email to another address, but Mailgun also allows you elect to post the message to your app: Mailgun will either send you the entire unparsed MIME message (if that’s your thing) or parse it for you and POST the parsed parameters. In both cases, they’ll transcode the message to UTF-8 which is a really nice bonus.
Using Mailgun Routes, Agape was able to forward all emails sent to [user]@agape.org.cn addresses to everyone’s personal email accounts. No migrations needed! What’s more, the API system allowed us to write a script that quickly imports hundreds of routes quickly and easily, using a .csv file. Let me show you what I mean.
1. First, we create a .csv file of source and forwarding address separated by commas, one pair per line, like so:
example1@agape.org.cn, somemailbox@hotmail.com
example2@agape.orgcn, someotherbox@gmail.com
2. Next, we create a function that calls the Mailgun API to “add a new route”.
1// php23function create_route($recipient, $routeto) {45 $ch = curl_init();67 curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);8 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);9 curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);10 curl_setopt($ch, CURLOPT_USERPWD, 'api:key-xxxxxxxxxxxxxxxx);11 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);1213 curl_setopt($ch, CURLOPT_URL, 'https://api.mailgun.net/v2/routes');14 curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');15 curl_setopt($ch, CURLOPT_POSTFIELDS, array('priority' => 1,16 'expression' => 'match_recipient("' . $recipient . '")',17 'action[1]' => 'forward("' . $routeto . '")',18 'description' => 'Created by Mailgun Routes Importer'));1920 $result = curl_exec($ch);21 $info = curl_getinfo($ch);22 curl_close($ch);23}
3. Then we create a function that parses the .csv file to an array, iterate through it, and call the API function to add each route:
1// php23function run_importer() {4 $filepath = "fwdaddresses.csv";5 if(($handle = fopen($filepath, "r")) != FALSE) {6 // loop and import7 while (($addresses = fgetcsv($handle, 1000, ",")) !== FALSE) {8 $recipient = trim($addresses[0]);9 $routeto = trim($addresses[1]);1011 create_route($recipient, $routeto);12 }13 }14}
4. Then simply make sure the script and .csv file are in the same directory (or change $filepath variable to match your .csv file’s filepath) and run the script: run_importer();
It’s really quite simple. Using the Mailgun Routes API, we were able to quickly add hundreds of forwarding addresses so that Agape employees and volunteers worldwide can easily access their Agape email. Thanks Mailgun!
Learn about our Deliverability Services
Looking to send a high volume of emails? Our email experts can supercharge your email performance. See how we've helped companies like Lyft, Shopify, Github increase their email delivery rates to an average of 97%.
Last updated on August 28, 2020
How Do Users on G2 Rate Mailgun?
Building the Best Email Experience for Creators - Flipsnack’s Story
Intelligent Email Forwarding With Mailgun
When Transactional Email Preps 4 Million Contracts For E-Signature Every Month
Sending Millions Of Job Alerts 24/7 With The Mailgun Email API
Getting Started With Mailgun: An Introduction To The Platform
Behind The Scene At Jungle Disk: Reliable Email Communications With Mailgun
Zipbooks Switched From Mandrill To Mailgun Using Laravel
Easily Integrate Forms Into Your App With Mailgun And Form.Io
Easily Send Email From Your Mobile App Using Appery.Io And Mailgun
InboxReady x Salesforce: The Key to a Stronger Email Deliverability
Become an Email Pro With Our Templates API
Google Postmaster Tools: Understanding Sender Reputation
Navigating Your Career as a Woman in Tech
Implementing Dmarc – A Step-by-Step Guide
Email Bounces: What To Do About Them
Announcing InboxReady: The deliverability suite you need to hit the inbox
Black History Month in Tech: 7 Visionaries Who Shaped The Future
How To Create a Successful Triggered Email Program
Designing HTML Email Templates For Transactional Emails
InboxReady x Salesforce: The Key to a Stronger Email Deliverability
Implementing Dmarc – A Step-by-Step Guide
Announcing InboxReady: The deliverability suite you need to hit the inbox
Designing HTML Email Templates For Transactional Emails
Email Security Best Practices: How To Keep Your Email Program Safe
Mailgun’s Active Defense Against Log4j
Email Blasts: The Dos And Many Don’ts Of Mass Email Sending
Email's Best of 2021
5 Ideas For Better Developer-Designer Collaboration
Mailgun Joins Sinch: The Future of Customer Communications Is Here
Always be in the know and grab free email resources!
By sending this form, I agree that Mailgun may contact me and process my data in accordance with its Privacy Policy.