BroiSatse / mailgunner

A Ruby wrapper for the Mailgun API

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

mailgunner

A Ruby wrapper for the Mailgun API.

Installation

$ gem install mailgunner

Quick start

require 'mailgunner'

mailgun = Mailgunner::Client.new({
  domain: 'samples.mailgun.org',
  api_key: 'key-3ax6xnjp29jd6fds4gc373sgvjxteol0'
})

response = mailgun.get_stats(limit: 5)

Environment variables

Best practice for storing credentials for external services is to use environment variables, as described by 12factor.net/config. 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.

Email validation

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

require 'mailgunner'

public_key = 'pubkey-5ogiflzbnjrljiky49qxsiozqef5jxp7'

mailgun = Mailgunner::Client.new(api_key: public_key)

response = mailgun.validate_address('john@gmail.com')

About

A Ruby wrapper for the Mailgun API