Working with Mailgun Bounce Lists

Manipulate Mailgun Bounce Lists: Show, Add, and Delete Email Addresses. All from the terminal.

I recently came across a situation where a client reached their disk usage limit. As a result, they were unable to receive emails. This went un-noticed for a couple days (I didn’t manage the server at the time, I do now).

This client has a couple different WordPress sites with several employees receiving various notification emails. All their sites use Mailgun and the Mailgun WordPress plugin for sending emails. During the time they were unable to receive email, a few employee email addresses got placed on a Mailgun bounce list with a status of 550 Administrative prohibition.

For some background, here’s how Mailgun describes a bounce, as found in the Mailgun documentation:

Bounce list stores events of delivery failures due to permanent recipient mailbox errors such as non-existent mailbox. Soft bounces (for example, mailbox is full) and other failures (for example, ESP rejects an email because it thinks it is spam) are not added to the list.

Subsequent delivery attempts to an address found in a bounce list are prevented to protect your sending reputation.

mailgun-bounced

I first noticed the bounce issue in the logs, like in the image below. After not being able to find a way to manage email addresses on the bounce list from the browser, I hit up Google and was pleased to find that you can interact with Mailgun bounce lists via their API.

Show Email Addresses in the Mailgun Bounce List

To list email addresses on the bounce list, do something like this on the terminal/command line, replacing key-xxx-xxx with your actual Mailgun API key:

curl -s --user 'api:key-xxx-xxx' -G https://api.mailgun.net/v3/mg.longrendev.io/bounces
json-prettifier

You can find your Mailgun API key on the Mailgun dashboard, under API Keys. The Mailgun API will return JSON, which is a bit difficult to read in the terminal. I usually copy the output and paste it into this JSON formatter, which makes the data much easier to read, as you can see in the screenshot above.

Even when the formatted JSON in it’s raw form is easier to read. See, here’s the returned JSON, in it’s original form:

Now here’s the pretty, formatted JSON as raw text:

Much easier to read, right? Those of you using REST clients like Postman will have your results automatically prettified, removing the need using a site like the JSON formatter I typically use.

Delete an Email Address from the Mailgun Bounce List

If you’ve found an email address you’d like to remove from the Mailgun bounce list, or already know the email you want to remove, do this from a terminal and replace email@somedomain.com with the real email address to delete. And of course, replace key-xxx-xxx with your actual Mailgun API key:

curl -s --user 'api:key-xxx-xxx' -H "Accept: application/json" -X DELETE https://api.mailgun.net/v3/mg.longrendev.io/bounces/email@somedomain.com

Add an Email Address to the Mailgun Bounce List

Sometimes you may wish to manually add an email address to the Mailgun bounce list. This can be done very easily with the CURL command below. It will add email@somedomain.com to the Mailgun bounce list, so make sure to change that to the email you really want to add to the list.

curl -s --user 'api:key-7g0wl66k2hxonzq5-0nbzhw68r2oc8n8' https://api.mailgun.net/v3/mg.longrendev.io/bounces -F address='email@somedomain.com'

What Else?

Not much concerning Mailgun bounce lists specifically. It’s possible to add multiple addresses to a bounce list at once, but that gets a little more difficult from the terminal as it requires sending JSON to the Mailgun API. Using a client like Postman would be a better option if you intend on sending much data.

The Mailgun API can be used to do all sorts of stuff, like pull stats and to create new domains. It’s a powerful API and one of my favorites to work with.

How do you prefer to send emails from your websites?

View Results

Loading ... Loading ...
9+

RemindToRead: Email Users a Reminder to Finish Reading Your Articles

Provide your users a world-class post-visit experience

I liked the idea of using RemindToRead.com on this site when I saw it on Hacker News the other day. I got in touch with Leonard Bogdonoff and expressed interest. He, in turn, offered to let me test it out here at longren.io.

Leonard setup some JS for my site for a quick test and gave me all the necessary code in a shared Google Doc. Took all of 5 minutes to get setup.

You can see it in action at the end of every post here at longren.io. It appears at the very end of every post, but only when viewing an individual post. The button looks like this:
remind-to-read-button

Is RemindToRead Ready For Production?

Getting closer, just from the changes I saw on the dashboard today and the very straight-forward registration process. Signup requires minimal effort. Just enter your email, choose a password, receive an email containing a confirmation link, click the confirmation link, update password, and continue on with setup. A temporary email sent after user signup can be seen below.
remind-to-read-welcome-email-temporary

The current iteration of the dashboard is not quite finished, but is very functional as it stands, even it’s early stages. It provides easy to follow instructions for adding RemindToRead code to your website. Just include some JavaScript and add this little snippet where you want the RemindToRead button to show:

<a href="#" class="later-button-el"></a>

Here’s what the dashboard currently looks like:
remindtoread-dash

I simply added the code above to my relevant template file so that it’s displayed at the end of every post, but is only shown when viewing a single post. So you won’t see the button on archive pages, tags pages, category pages, search results, etc.

A WordPress Plugin Coming

A GitHub repo already exists for a WordPress plugin, I’ve not tried it out yet, but plan to later today and will report back. I know there’s been a lot of core changes to RemindToRead recently, the WordPress plugin may have some catching up to do.

The plugin looks pretty solid code-wise, after a real quick glance. Sounds like Leonard may want me to maintain the WordPress plugin, should be a piece of cake once the core of everything starts to take its final shape.

8+

Use Docker for Fast WordPress Development Environments

A Dockerfile That Provides Quick WordPress Development Environments

Back in May of this year I started playing around with Docker quite a bit. Took me a bit to wrap my brain around everything Docker can do, wish I had read this article from Adam Ierymenko before starting.

Anyway, Docker describes itself as such:

Docker is an open platform for building, shipping and running distributed applications. It gives programmers, development teams and operations engineers the common toolbox they need to take advantage of the distributed and networked nature of modern applications.

I’m not using Docker to it’s fullest extent, not even close. I mostly use it for setting up quick WordPress development environments for building client sites or just to do some testing.

I came across an outdated Dockerfile that had exactly what I needed but lacked the ability to SSH to the Docker container. I forked it on GitHub and added some modifications (like SSH).

It’s on the Docker Hub Registry, making it super easy to use. There’s a few items on the to-do list, but the one I want to take care of first is adding support for Docker Compose, which will make installation even easier.

To get started with this Docker image, you just need to have Docker installed and then run the following command:

sudo docker pull tlongren/docker-wordpress-nginx-ssh:latest

Once you’ve got the Docker image pulled, fire up a new container like with the command below. It will create a new Docker container named project-name.

sudo docker run -p 80:80 -p 2222:22 --name project-name -d tlongren/docker-wordpress-nginx-ssh:latest

Give it a bit to get everything setup then navigate to http://127.0.0.1:80 in your browser to access your new WordPress install.

For more information I suggest checking out the readme. Every time that I push commits to GitHub, a new build of the Docker image will automatically be built as I’ve got it setup as an automated build repository at the Docker Hub Registry. Pretty nifty.

So, I’m relatively new to Docker, if you’re a pro and see something I should be doing differently, please let me know. Any advice on setting up Docker Compose for this project would be great, too (if I’m not mistaken, it just involved linking multiple containers together).

Do you use Docker?

View Results

Loading ... Loading ...
8+

Use Composer in Your WordPress Plugin or Theme

Simple Tutorial Showing How To Use Composer in Your WordPress Plugin or Theme

I love Composer. It just makes including libraries or scripts in your app incredibly easy. So easy that it’s stupid not to use it (in many, if not most cases).

The number of libraries/scripts available on Packagist is astounding, all of which can be included in your plugin with Composer. Packagist is the main Composer repository. It basically aggregates all types of PHP packages that can be installed via Composer.

I’d never used Composer with a proprietary WordPress plugin before. The plugin is for a client so it’ll never be available to the public.

Here’s the steps I took to make this WordPress plugin compatible with Composer so that I can easily bring in third-party libraries.

We’ll be using mailgun-php throughout this example, as the plugin that inspired this post uses Mailgun to send all sorts of emails.

1. First, install composer on your server.

I install Composer globally, like so:

curl -sS https://getcomposer.org/installer | php<br>sudo mv composer.phar /usr/local/bin/composer

2. Add Mailgun as a dependency.

cd /path/to/plugin/
composer require mailgun/mailgun-php:~1.7.2

3. Check your composer.json file.

We’re including Mailgun and guzzle from Packagist. Your composer.json file should look similar to the example below.

4. Tell composer to install Mailgun.

tyler@yourmachine:~/path/to/plugin$ composer install

5. Autoload Our Mailgun Classes in Our Plugin.

The following should go in your plugin-name.php file, before any other PHP code.

<?php
require 'vendor/autoload.php';
use MailgunMailgun;

You can now use Mailgun in your WordPress plugin or theme, some basic examples of using Mailgun can be found on GitHub and in their official documentation.

2+

Fix StanleyWP WordPress Theme Portfolio Grid

Fix display of portfolio grid rows

Back in September of 2014 I wrote about using the StanleyWP WordPress theme for a portfolio site. After I added some projects, I noticed the grid on the Portfolio page template wasn’t displaying rows correctly. I even noted it in my original post, towards the end.

I’ve had a few people contact me about how to fix the StanleyWP portfolio grid issue, and earlier today Arun left a comment asking how to fix the grid issue.

You need to be using a child theme for this, it’s just good practice. If you don’t know how to create a child theme, read my post on creating a child theme. It’s really easy to do, but may require you to reset your menu or some widgets after changing to the child theme.

Anyway, Arun confirmed that this gist fixed the problem for him.

Just save that code as template-portfolio.php and put it in your child theme directory. Your portfolio should now show three projects per row. No CSS or anything else needs to be modified, just that one page template.

Let me know if you have any issues or questions.

2+