Sha256: a6405e26e432515f772ad00617aa298f6650c776589e14fb4d1f6ce3e2a55586

Contents?: true

Size: 1.16 KB

Versions: 3

Compression:

Stored size: 1.16 KB

Contents

# test using: ruby example.rb
# using ruby 2.2.2p95 (2015-04-13 revision 50295) [x86_64-darwin14]
# attachment is sent but only a corrupted 1k file

require_relative "lib/sendgrid-ruby.rb"

require 'dotenv'
Dotenv.load

# sendgrid_username = ENV['SENDGRID_USERNAME']
# sendgrid_password = ENV['SENDGRID_PASSWORD']
sendgrid_apikey = ENV['SENDGRID_APIKEY']

# client = SendGrid::Client.new(api_user: sendgrid_username, api_key: sendgrid_password)

client = SendGrid::Client.new do |c|
  # c.api_user = sendgrid_username
  c.api_key = sendgrid_apikey
end

mail = SendGrid::Mail.new do |m|
  m.to = 'elmer.thomas@sendgrid.com'
  m.from = 'elmer@thinkingserious.com'
  m.subject = 'Hello world!'
  m.text = 'I heard you like the beach.'
  m.html = 'I heard you like the beach <div><img src="cid:beach"></div>'
end
mail.add_content('/tmp/beach.jpg', 'beach')
mail.add_attachment('/tmp/report.pdf', 'report.pdf')
result = client.send(mail)
puts result.code
puts result.body

# puts client.send(SendGrid::Mail.new(to: 'elmer.thomas@sendgrid.com', from: 'elmer@thinkingserious.com', subject: 'Hello world!', text: 'Hi there, testing from Ruby!', html: '<b>Hi there, testing from Ruby!</b>'))

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
sendgrid-ruby-1.1.5 example.rb
sendgrid-ruby-1.0.5 example.rb
sendgrid-ruby-1.0.4 example.rb