Skip to contentSkip to navigationSkip to topbar
Rate this page:
On this page

v3 API Ruby Code Example


(information)

Info

We recommend using SendGrid Ruby, our client library, available on GitHub(link takes you to an external page), with full documentation.

(information)

Info

Do you have an API Key(link takes you to an external page) yet? If not, go get one. You're going to need it to integrate!


Using SendGrid's Ruby Library

using-sendgrids-ruby-library page anchor

_16
# using SendGrid's Ruby Library
_16
# https://github.com/sendgrid/sendgrid-ruby
_16
require 'sendgrid-ruby'
_16
include SendGrid
_16
_16
from = SendGrid::Email.new(email: 'test@example.com')
_16
to = SendGrid::Email.new(email: 'test@example.com')
_16
subject = 'Sending with SendGrid is Fun'
_16
content = SendGrid::Content.new(type: 'text/plain', value: 'and easy to do anywhere, even with Ruby')
_16
mail = SendGrid::Mail.new(from, subject, to, content)
_16
_16
sg = SendGrid::API.new(api_key: ENV['SENDGRID_API_KEY'])
_16
response = sg.client.mail._('send').post(request_body: mail.to_json)
_16
puts response.status_code
_16
puts response.body
_16
puts response.headers


Rate this page: