Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

450
Visualizações
Send transactional email with SendGrid on a Rails app

I am trying to send a transactional email using Sendgrid upon client booking on a Rails application.

I did create a dynamic template as required. When I make a POST request to https://api.sendgrid.com/v3/mail/send with POSTMAN using the right body and my Sendgrid API key, it works, I do receive the confirmation email.

However, I am a Rails newbie and I really don't know how to proceed with the piece of code provided in the docs:

require 'sendgrid-ruby'
include SendGrid

sg = SendGrid::API.new(api_key: ENV['SENDGRID_API_KEY'], impersonate_subuser: The subuser's username. This header generates the API call as if the subuser account was making the call.)
data = JSON.parse('{
  "name": "example_name",
  "generation": "dynamic"
}')

response = sg.client.templates.post(request_body: data)
puts response.status_code
puts response.headers
puts response.body

Thanks in advance for your help!

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

Twilio SendGrid developer evangelist here.

Check out the documentation here that shows all the options you can use to send an email with the Ruby library (excuse the use of include).

Based on the docs, here's a quick snippet that should cover your needs:

require 'sendgrid-ruby'

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

mail.from = SendGrid::Email.new(email: "YOUR_FROM_ADDRESS")
mail.subject = "Your fancy, exciting subject line"
mail.template_id = "YOUR_TEMPLATE_ID"

personalization = SendGrid::Personalization.new
personalization.add_to(SendGridEmail.new(email: 'YOUR_CUSTOMER_EMAIL'))
personalization.add_dynamic_template_data({
  "name" => "example_name",
  "generation" => "dynamic"
})
mail.add_personalization(personalization)

sg.client.mail._("send").post(request_body: mail.to_json)

Take a look at this specific example in the SendGrid Ruby library docs too.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda