Back to main menu

Product

The official Mailgun Ruby gem is here

Ruby has been added to our list of SDKs! Want to learn more about how to send email through Mailgun with Ruby? Read more...

PUBLISHED ON

PUBLISHED ON

Today, we’re happy to announce that we’ve added Ruby to the list of official Mailgun SDKs. Just like our PHP SDK, we’ve included some utilities like Message Builder, Batch Sending and Opt-in Hander to simplify common development tasks. We’re looking forward to collaborating with the Ruby community to make the SDK even better over time. You can access the SDK on Github.

For those not familiar with an SDK, let’s first review what’s required to send a message using the standard HTTPS Ruby library.

Today, we’re happy to announce that we’ve added Ruby to the list of official Mailgun SDKs. Just like our PHP SDK, we’ve included some utilities like Message Builder, Batch Sending and Opt-in Hander to simplify common development tasks. We’re looking forward to collaborating with the Ruby community to make the SDK even better over time. You can access the SDK on Github.

For those not familiar with an SDK, let’s first review what’s required to send a message using the standard HTTPS Ruby library.

Sending a message:

The above will send a message using the Mailgun API, however, there’s a lot of code there that, while important, is complicated, and rather confusing.

Using our new SDK, we’ve managed to reduce the amount of code required to just a few lines.

Sending a message with Mailgun Ruby SDK:

Obtaining Events with the Mailgun Ruby SDK:

All HTTP actions return a response object, which can be converted to a hash or YAML.

Let’s say we’d like to get the next 25 results, using the same query. Just issue “next” on the “mg_events” object. The SDK keeps track of the Events API pagination links.

result = mg_events.next

Note: If the result set is less than your limit, do not worry. A subsequent query of “next” will return the next 25 results since the last time you called “next” or “get”.

Message Builder

Creating an array of parameters can be difficult for some code implementations, so we’ve included a class that allows you to make method calls that automatically build a properly formed array of message parameters.

Sending a message with Mailgun Ruby SDK + Message Builder:

For a list of all available functions, check out the list on Github.

Batch Message

In addition to Message Builder, we have Batch Message. This class allows you to build a message and submit a template message in batches, up to 1,000 recipients per post. The benefit of using this class is that the recipients tally is monitored and will automatically submit the message to the endpoint when you’ve added the 1,000th recipient. This means you can build your message and begin iterating through your database. Forget about sending the message, the SDK will keep track of posting to the API when necessary.

Sending a message with Mailgun Ruby SDK + Batch Message:

As you can see, Batch Message actually extends Message Builder. All functions available in Message Builder are available in Batch Message. Check out the full documentation on Github.

Opt-In Handler

Finally, we have built a simple double opt-in handler to help you generate unique opt-in links. The opt-in handler also uses our address validation service to validate the accuracy of the email addresses.

The typical flow for using this class would be as follows: Recipient Requests Subscribe -> [Validate Recipient Address] -> [Generate Opt In Link] -> [Email Recipient Opt In Link] Recipient Clicks Opt In Link -> [Validate Opt In Link] -> [Subscribe User] -> [Send final confirmation]

It is best to use this class for your website subscription forms, so you’ll need a web server accessible to the internet to handle the validation link click.

Since each implementation will be rather unique, see the Github documentation for usage examples of this class.

Let us know what you think. Is there something else you’d like to see in the SDK? Or something you love. We’d appreciate your feedback!

Happy Sending!

Sign Up

It's easy to get started. And it's free.

See what you can accomplish with the world’s best email delivery platform.

Related readings

Bulk validations: Accurate and fast AF

Cleaning an old email list is one of those must needed chores that nobody really wants to do...

Read More

Mailgun for non-devs: Leveraging an email marketing platform

This guest post comes from Ongage, a front-end email marketing platform that integrates nicely with ESPs like Mailgun and empowers...

Read More

How to improve your email deliverability for the future of email

If your customers aren’t getting your emails, then there’s a good chance that your email program needs some refreshing with these email deliverability tips taken from Email Camp: MessageMania speaker and industry pro, Laura Atkins.

Read More

Popular posts

Email inbox.

Email

5 min

Build Laravel 11 email authentication with Mailgun and Digital Ocean

Read More

Mailgun statistics.

Product

4 min

Sending email using the Mailgun PHP API

Read More

Statistics on deliverability.

Deliverability

5 min

Here’s everything you need to know about DNS blocklists

Read More

See what you can accomplish with the world's best email delivery platform. It's easy to get started.Let's get sending
CTA icon