How to Send Email with Ruby

Introduction

Table of contents

Requirements to send email with Ruby

1. Set up your transactional email service

Select your email service provider

Create your SendGrid account

Authenticate your domain in SendGrid

Create your SendGrid API key

2. Set up the email channel in Courier

Sign up for Courier

Integrate your email service provider

3. Design and preview your email in Courier

Use the visual editor to design your email

Customize your brand

Create a test event

Preview your email

Publish your email

4. Send emails from your Ruby app

Install the Courier Ruby gem

gem 'trycourier'
$ bundle install
$ gem install trycourier

Set your environment variables

Map your email notification to an event

Copy-paste the code snippet from Courier

require "trycourier"   begin
client = Courier::Client.new
res = client.send({
"event" => "New Account",
"recipient" => "User123",

"profile" => {
"email": "user123@example.com",
},
"data" => {
"username" => "User123",
"date" => "November 20, 2020"
}
})
puts res.code # the HTTP response code
puts res.message_id # if 200, this will be the Courier message ID for this notification
rescue Courier::ResponseError => re
puts re.message
rescue Courier::InputError => ie
puts ie.message end

Start sending emails from your Ruby app

Courier is the fastest way for developers to build notifications for their apps. With one API and easy-to-use UI trigger multi-channel notifications at scale.