---
"@context": https://schema.org
"@type": TechArticle
"@id": https://www.twilio.com/docs/sendgrid/for-developers/sending-email/v3-ruby-code-example#article
headline: v3 API Ruby Code Example
description: Integrate SendGrid Ruby, an accessible client library on GitHub, into your system. Obtain an API Key for smooth integration.
url: https://www.twilio.com/docs/sendgrid/for-developers/sending-email/v3-ruby-code-example
inLanguage: en
dateModified: 2026-07-23T16:57:51.000Z
author:
  "@type": Organization
  name: Twilio Developer Education Team
publisher:
  "@type": Organization
  name: Twilio
---

# v3 API Ruby Code Example

> \[!NOTE]
>
> We recommend using SendGrid Ruby, our client library, [available on GitHub](https://github.com/sendgrid/sendgrid-ruby), with full documentation.

> \[!NOTE]
>
> Do you have an [API Key](https://app.sendgrid.com/settings/api_keys) yet? If not, go get one. You're going to need it to integrate!

## Using SendGrid's Ruby Library

The following example sends a single email with the Twilio SendGrid Ruby library. Set your API key in the `SENDGRID_API_KEY` environment variable, then build and send the message.

```ruby title="Send an email with the Twilio SendGrid Ruby library"
# using SendGrid's Ruby Library
# https://github.com/sendgrid/sendgrid-ruby
require 'sendgrid-ruby'
include SendGrid

from = SendGrid::Email.new(email: 'test@example.com')
to = SendGrid::Email.new(email: 'test@example.com')
subject = 'Sending with SendGrid is Fun'
content = SendGrid::Content.new(type: 'text/plain', value: 'and easy to do anywhere, even with Ruby')
mail = SendGrid::Mail.new(from, subject, to, content)

sg = SendGrid::API.new(api_key: ENV['SENDGRID_API_KEY'])
response = sg.client.mail._('send').post(request_body: mail.to_json)
puts response.status_code
puts response.body
puts response.headers
```
