Skip to content

Instantly share code, notes, and snippets.

@sendgrid-gists
Last active July 6, 2016 15:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sendgrid-gists/4be3a76b716e16c274c2ad0f6a99e9b4 to your computer and use it in GitHub Desktop.
Save sendgrid-gists/4be3a76b716e16c274c2ad0f6a99e9b4 to your computer and use it in GitHub Desktop.
v3 "Hello World" for email, using SendGrid with Ruby.
# using SendGrid's Ruby Library
# https://github.com/sendgrid/sendgrid-ruby
require 'sendgrid-ruby'
include SendGrid
from = Email.new(email: 'test@example.com')
to = Email.new(email: 'test@example.com')
subject = 'Sending with SendGrid is Fun'
content = Content.new(type: 'text/plain', value: 'and easy to do anywhere, even with Ruby')
mail = 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment