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
  • Configuring Enveloop in your Rails app
  • Update your Initializer
  • Create an Enveloop Mailer
  • Modify your Enveloop Mailer to set up a Connection
  • Send a Message from your Rails app
  • Additional Information
  • Contributing
  1. Enveloop API
  2. Languages and Frameworks

Ruby on Rails

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 on Rails apps.

Provided are some quick docs for setting up Enveloop inside your Ruby on Rails app and interacting with the Enveloop Ruby gem.

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.

Configuring Enveloop in your Rails app

Update your Initializer

Add/update the following lines in your respective Rails environments file.

# remember to never include production keys in files you check into repos.

ENV['ENVELOOP_API_KEY'] = 'ENVELOOP_API_KEY'

config.action_mailer.delivery_method = :enveloop

config.action_mailer.enveloop_settings = { 
  api_key: ENV['ENVELOOP_API_TOKEN']
}

Create an Enveloop Mailer

From your command line, use a Rails generator to create a new Enveloop Mailer.

$ rails generate mailer EnveloopMailer

Modify your Enveloop Mailer to set up a Connection

Now that the mailer is created, you can modify it and add in a custom method, based on your application, to call the send_message method in the Enveloop API.

class EnveloopMailer < ActionMailer::Base

   include Rails.application.routes.url_helpers 

   def new_comment_email(recipient, comment)
      enveloop.send_message(
         template: 'new-comment',
         to: recipient,
         from: 'hello@myapp.com',
         subject: subject,
         template_variables:{
            account_url: 'https://myapp.com',
            user_comment: comment
         }
      )
   end

   private

   def enveloop
      @enveloop ||= Enveloop::Client.new(api_key: ENV['ENVELOOP_API_KEY']) 
   end

end

Send a Message from your Rails app

Now, all that is left is to make a call to send a message, via Enveloop, whenever you need it.

EnveloopMailer.new_comment_email(
    @comment.user_email_address, 
    @comment.body
).deliver_now

Additional Information

Contributing

This documentation assumes that you have a mostly standard Rails app up and running. Obviously, there are variations to the mailer types you can use -- and we cover some of this, including , on the Enveloop Blog.

You can find additional information for other methods, sending text/SMS messages, and more by viewing the .

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
Devise
Enveloop Language page for Ruby
https://github.com/enveloophq/enveloop-ruby