Created: 2013-01-02 11:21
Updated: 2019-01-16 14:28
License: other


Gem Version Build Status

Ruby client for the Mailgun API.


$ gem install mailgunner

Quick start

require 'mailgunner'

mailgun ={
  domain: '',
  api_key: 'key-3ax6xnjp29jd6fds4gc373sgvjxteol0'

response = mailgun.get_domains

response['items'].each do |item|
  p item.values_at('id', 'name')

Storing the API key

Best practice for credentials is to store them in the environment. Mailgunner::Client defaults to extracting the domain and api_key values it needs from the MAILGUN_API_KEY and MAILGUN_SMTP_LOGIN environment variables—these will exist if you are using Mailgun on Heroku, or you can set them manually.

ActionMailer integration

Mailgunner integrates with ActionMailer. If you are using Rails, you can use Mailgunner to send mail via Mailgun by adding the following line to config/environments/production.rb:

config.action_mailer.delivery_method = :mailgun

If for some reason you can't set the required ENV variables, you can configure Mailgunner through ActionMailer settings:

config.action_mailer.mailgun_settings = {
  domain: '',
  api_key: 'your-api-key'

Outside of Rails you can set ActionMailer::Base.delivery_method directly.

Specifying the region

Mailgun offers both a US and EU region to send your e-mail from. Mailgunner uses the US region by default. If you wish to use the EU region set the api_host config option like so:

mailgun ={
  domain: '',
  api_key: 'key-3ax6xnjp29jd6fds4gc373sgvjxteol0',
  api_host: ''

Email validation

If you only need to use Mailgun's email address validation service, you can instead use your Mailgun public key to authenticate like this:

require 'mailgunner'

public_key = 'pubkey-5ogiflzbnjrljiky49qxsiozqef5jxp7'

mailgun = public_key)

response = mailgun.validate_address('')
Cookies help us deliver our services. By using our services, you agree to our use of cookies Learn more