Coder Social home page Coder Social logo

Getting started about sendgrid-ruby HOT 3 CLOSED

sendgrid avatar sendgrid commented on August 17, 2024
Getting started

from sendgrid-ruby.

Comments (3)

pmackay avatar pmackay commented on August 17, 2024 1

@thinkingserious I'd like to clarify, is the sendgrid-rails gem that @MincePie lists above needed at all? My understanding is the sendgrid-ruby gem is completely separate.

from sendgrid-ruby.

thinkingserious avatar thinkingserious commented on August 17, 2024

Hi @MincePie!

Thanks for reaching out to us! Following are the answers to your questions:

Q1: This library handles that for you with this call: sg = SendGrid::API.new(api_key: ENV['SENDGRID_API_KEY'])

Q2: Here is some example code for sending a template:

sg = SendGrid::API.new(api_key: ENV['SENDGRID_API_KEY'])

email = SendGrid::Mail.new
email.from = SendGrid::Email.new(email: "[email protected]", name: "Example Name")
email.subject = "Your Email's Subject"

p = SendGrid::Personalization.new
p.to = SendGrid::Email.new(email: "[email protected]", name: "Example User")
p.substitutions = SendGrid::Substitution.new(key: "key1", value: "value1")
p.substitutions = SendGrid::Substitution.new(key: "key2", value: "value2")

email.personalizations = p
email.template_id = "[YOUR TEMPLATE ID]"

response = sg.client.mail._('send').post(request_body: email.to_json)

puts response.status_code
puts response.body
puts response.headers

Q3: Here are some details about fluent interfaces: https://sendgrid.com/blog/using-ruby-to-implement-a-fluent-interface-to-any-restful-api. In your case, I would not worry about it.

You would add this code right after the point in your code where you would like to trigger the email.

Please let me know if you have further questions.

With Best Regards,

Elmer

from sendgrid-ruby.

thinkingserious avatar thinkingserious commented on August 17, 2024

@pmackay,

Good catch. No, that is a third party library not related to ours.

from sendgrid-ruby.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.