v3 API Ruby Code Example
(information)
Info
We recommend using SendGrid Ruby, our client library, available on GitHub, with full documentation.
(information)
Info
Do you have an API Key yet? If not, go get one. You're going to need it to integrate!
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.
1# using SendGrid's Ruby Library2# https://github.com/sendgrid/sendgrid-ruby3require 'sendgrid-ruby'4include SendGrid56from = SendGrid::Email.new(email: 'test@example.com')7to = SendGrid::Email.new(email: 'test@example.com')8subject = 'Sending with SendGrid is Fun'9content = SendGrid::Content.new(type: 'text/plain', value: 'and easy to do anywhere, even with Ruby')10mail = SendGrid::Mail.new(from, subject, to, content)1112sg = SendGrid::API.new(api_key: ENV['SENDGRID_API_KEY'])13response = sg.client.mail._('send').post(request_body: mail.to_json)14puts response.status_code15puts response.body16puts response.headers