Git Product home page Git Product logo

mailgun-ruby's Introduction

Mailgun-Ruby

Build Status Gem Version

This is the Mailgun Ruby Library. This library contains methods for easily interacting with the Mailgun API. Below are examples to get you started. For additional examples, please see our official documentation at http://documentation.mailgun.com

Installation

Via RubyGems

gem install mailgun-ruby

Gemfile:

gem 'mailgun-ruby', '~>1.0.3', require: 'mailgun'

Include

require 'mailgun'

Usage

Here's how to send a message using the library:

# First, instantiate the Mailgun Client with your API key
mg_client = Mailgun::Client.new "your-api-key"

# Define your message parameters
message_params = {:from    => 'bob@sending_domain.com',
                  :to      => '[email protected]',
                  :subject => 'The Ruby SDK is awesome!',
                  :text    => 'It is really easy to send a message!'}

# Send your message through the client
mg_client.send_message "sending_domain.com", message_params

Or obtain the last couple log items:

# First, instantiate the Mailgun Client with your API key
mg_client = Mailgun::Client.new "your-api-key"

# Define the domain you wish to query
domain = "example.com"

# Issue the get request
result = mg_client.get("#{domain}/events", {:event => 'delivered'})

Response

The results are returned in a Response class:

result = mg_client.get("#{domain}/events", {:event => 'delivered'})

# To Ruby standard Hash.
result.to_h

# To YAML.
result.to_yaml

# Or raw JSON
result.body

Here's an example, breaking out the response:

mg_client = Mailgun::Client.new("your-api-key")

message_params = {:from    => '[email protected]',
                  :to      => '[email protected]',
                  :subject => 'The Ruby SDK is awesome!',
                  :text    => 'It is really easy to send a message!'}

result = mg_client.send_message("example.com", message_params).to_h!

message_id = result['id']
message = result['message']

Debugging

Debugging the Ruby Library can be really helpful when things aren't working quite right. To debug the library, here are some suggestions:

Set the endpoint to Mailgun's Postbin. A Postbin is a web service that allows you to post data, which is then displayed through a browser. This allows you to quickly determine what is actually being transmitted to Mailgun's API.

Step 1 - Create a new Postbin. Go to http://bin.mailgun.net. The Postbin will generate a special URL. Save that URL.

Step 2 - Instantiate the Mailgun client using Postbin.

Tip: The bin id will be the URL part after bin.mailgun.net. It will be random generated letters and numbers. For example, the bin id in this URL, http://bin.mailgun.net/aecf68de, is "aecf68de".

# First, instantiate the Mailgun Client with your API key
mg_client = Mailgun::Client.new("your-api-key", "bin.mailgun.net", "aecf68de", ssl = false)

# Define your message parameters
message_params = {:from    => 'bob@sending_domain.com',
                  :to      => '[email protected]',
                  :subject => 'The Ruby SDK is awesome!',
                  :text    => 'It is really easy to send a message!'}

# Send your message through the client
mg_client.send_message("sending_domain.com", message_params)

For usage examples on each API endpoint, head over to our official documentation pages. Or the Snippets file.

This SDK includes a Message Builder, Batch Message, Opt-In Handler and Events component.

Message Builder allows you to quickly create the array of parameters, required to send a message, by calling a methods for each parameter. Batch Message is an extension of Message Builder, and allows you to easily send a batch message job within a few seconds. The complexity of batch messaging is eliminated!

Support and Feedback

Be sure to visit the Mailgun official documentation website for additional information about our API.

If you find a bug, please submit the issue in Github directly. Mailgun-Ruby Issues

As always, if you need additional assistance, drop us a note through your Control Panel at https://mailgun.com/cp/support.

mailgun-ruby's People

Contributors

amrnt avatar brandonweiss avatar davidbalbert avatar glycerine avatar iffyuva avatar jeremyschlatter avatar mide avatar nneal avatar porbas avatar svc-scm avatar travelton avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.