Skip to content

Instantly share code, notes, and snippets.

@thinkingserious
Created January 21, 2016 19:58
Show Gist options
  • Save thinkingserious/fd5e407a41f1e2b7225f to your computer and use it in GitHub Desktop.
Save thinkingserious/fd5e407a41f1e2b7225f to your computer and use it in GitHub Desktop.
Sending an email using an template using the sendgrid-ruby library
require 'sendgrid-ruby'
require 'dotenv'
Dotenv.load
sendgrid_apikey = ENV['SENDGRID_APIKEY']
client = SendGrid::Client.new do |c|
c.api_key = sendgrid_apikey
end
recipient = SendGrid::Recipient.new('elmer.thomas@sendgrid.com')
recipient.add_substitution(':name', 'Elmer')
recipients = []
recipients << recipient
template = SendGrid::Template.new('13b8f94f-bcae-4ec6-b752-70d6cb59f932')
mail_defaults = {
from: 'dx@sendgrid.com',
html: '<h1>I like email</h1>',
text: 'I like email',
subject: 'Email is great',
}
mailer = SendGrid::TemplateMailer.new(client, template, recipients)
mailer.mail(mail_defaults)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment