Enveloop Docs
Sign up for Enveloop!
  • Enveloop Docs
  • Overview
    • ✨Features
  • Getting Started
    • Introduction to Enveloop
    • Creating a Template
    • Formatting / Dynamic Content
    • Sending a test message
    • Adding a Sending Domain
    • Deploying your first message
  • Product Guides
    • Elements
      • 🔋Table
    • Using Shared Sections
    • Markdown for Formatting
    • Mustache for Dynamic Content
    • Creating a Verified Sender
    • Logging
    • Monitoring
    • Webhooks
    • Themes
  • Integrations
    • Do I need integrations?
    • SMS Integrations
      • Twilio
      • TextGrid
    • Email Integrations
      • SendGrid
      • Postmark
      • Mailgun
      • Amazon SES
      • SMTP
        • ✉️Amazon SES
        • ✉️Gmail SMTP
        • ✉️Google Domain SMTP Relay
    • Partner Integrations
      • Fly.io
  • Enveloop API
    • Getting Started with Enveloop API
    • Core API Endpoints
      • Connecting to the Enveloop API
      • POST /messages
      • GET /templates/:slug
    • Languages and Frameworks
      • 🟢NodeJS
      • 🏮Ruby on Rails
      • 🟡Python
      • 🏮Ruby
  • Settings
    • Sending IPs
  • Company
    • About Us
    • 👩‍⚖️Terms of Service
    • 😎Privacy Policy
Powered by GitBook
On this page
  • Installing the Enveloop Ruby Gem
  • Using the Enveloop Gem
  • Setting up a Connection
  • Send an email message using an Enveloop Template
  • Send an email message using custom HTML
  • Send a text/SMS message using an Enveloop Template
  • Get information about an Enveloop template (variables, body HTML)
  • Contributing
  1. Enveloop API
  2. Languages and Frameworks

Ruby

Last updated 10 months ago

Enveloop provides the wrapper for our Enveloop API. It simplifies configuring and sending messages (email & SMS/text) via Enveloop inside your Ruby apps.

Installing the Enveloop Ruby Gem

There are a couple of ways to get started. Using , you can install it locally with the following command:

$ gem install enveloop

Additionally, you can add the following to your application's Gemfile:

gem 'enveloop'

After doing so, you can run the following terminal command:

$ bundle install

Using the Enveloop Gem

The Enveloop Gem includes helpful methods to interact with the Enveloop API, including:

  • send_message

  • template_info

We'll talk about how to use some of these methods in the notes to follow.

Setting up a Connection

First, let's set up a connection. You'll need to require the enveloop gem, define a client, and add in your Enveloop API token. Your API token is located in the Settings for each project you have on .

require 'enveloop'

enveloop = Enveloop::Client.new(api_key:`ENVELOOP_API_TOKEN')

Now that your connection is established, let's use a method to send a message.

(Note: This method call assumes that you have created a basic template in Enveloop and provides an example of a template variable you may use. Please alter according to how you have set up your template.)

Send an email message using an Enveloop Template

enveloop.send_message(
  template: 'welcome-email',
  to: 'user@email.com',
  from: 'welcome@myapp.com',
  subject: 'Welcome to My App!',
  template_variables: {
    first_name: 'John',
  }
)

Send an email message using custom HTML

If you want to send a message, via Enveloop, and not use an Enveloop template, you can remove the template argument from the method and include the html argument instead (it takes a custom HTML body and creates a structured email message to send out).

enveloop.send_message(
  html: '<h1>Hello John, Welcome to MyApp</h1>',
  to: 'user@email.com',
  from: 'welcome@myapp.com',
  subject: 'Welcome to MyApp',
)

Send a text/SMS message using an Enveloop Template

Along with email messages, you can also send text/SMS messages via Enveloop. In this example, the registration-complete template is an SMS template. Therefore, Enveloop can accept mobile numbers for to/from.

enveloop.send_message(
   template: 'registration-complete',
   to: '+14155551212',
   from: '+12056113369',
   template_variables: {
      first_name: 'Paul'
   }
)

Get information about an Enveloop template (variables, body HTML)

enveloop.template_info(template: 'welcome-email')

Contributing

Bug reports and pull requests are welcome on GitHub at . Additional information, including license, development procedures, and Code of Conduct are available in the source repository documentation.

🏮
Enveloop Ruby
RubyGems
Enveloop
https://github.com/enveloophq/enveloop-ruby