We recommend using SendGrid Ruby, our client library, available on GitHub, with full documentation.
The library does not officially support the V2 API, but you can use V2 with an older version of the library. For more information, see Continue Using V2 in Ruby.
_16# using SendGrid's Ruby Library_16# https://github.com/sendgrid/sendgrid-ruby_16require 'sendgrid-ruby'_16_16sendgrid = SendGrid::Client.new do |c|_16 c.api_key = 'SENDGRID_APIKEY'_16end_16_16email = SendGrid::Mail.new do |m|_16 m.to = 'test@sendgrid.com'_16 m.from = 'you@youremail.com'_16 m.subject = 'Sending with SendGrid is Fun'_16 m.html = 'and easy to do anywhere, even with Ruby'_16end_16_16sendgrid.send(email)
This example shows how to send email plain text and HTML email using Ruby. The gem Mail is required.
_23require 'mail'_23Mail.defaults do_23 delivery_method :smtp, { :address => "smtp.sendgrid.net",_23 :port => 587,_23 :domain => "yourdomain.com",_23 :user_name => "yourusername@domain.com",_23 :api_key => "your_api_key",_23 :authentication => 'plain',_23 :enable_starttls_auto => true }_23end_23_23mail = Mail.deliver do_23 to 'yourRecipient@domain.com'_23 from 'Your Name <name@domain.com>'_23 subject 'This is the subject of your email'_23 text_part do_23 body 'Hello world in text'_23 end_23 html_part do_23 content_type 'text/html; charset=UTF-8'_23 body '<b>Hello world in HTML</b>'_23 end_23end
To install the Mail gem please note that you need the OpenSSL library installed, then run the following:
_10gem install mail