sendgrid / sendgrid-ruby

The Official Twilio SendGrid Led, Community Driven Ruby API Library
https://sendgrid.com
MIT License
625 stars 322 forks source link

How to send mail using template from Design Library #407

Closed scottbarrow closed 4 years ago

scottbarrow commented 4 years ago

Issue Summary

I am able to send emails via the V3 API using a template_id, and dynamic_template_data, however when I use a template_id from the Design Library, the API responds with "Cannot use dynamic template data with a legacy template ID".
Is it possible to send using a designs template?

Thanks

Steps to Reproduce

  1. Send email using a template_id from the Design Library

Technical details:

courtsimas commented 4 years ago

I actually get a 202 response, but it doesn't actually read the "to" email in the personalizations array. So it never gets sent. It shows up in our Sendgrid activity page as undeliverable without a proper email address, although clearly I sent it in the api request.

I even used their v3 api docs curl/in-browser-terminal test, ON THEIR DOCS page, and put in my info (api key, email address, etc), and it still didn't go through. Something's definitely up with their system.

salsadeanguila commented 4 years ago

I'm having the same issue as @courtsimas. I have followed their examples and tried different things but it's not working. The add_to method it's not working.

courtsimas commented 4 years ago

I actually got it to work. It was the following, in combination with a good API Key that had full access.

    mail = SendGrid::Mail.new
    mail.template_id = 'd-something123'
    mail.asm = SendGrid::ASM.new(group_id: 01234)
    mail.from = Email.new(email: 'ex@example.com', name: 'the name')
    mail.subject = 'subject'
    personalization = Personalization.new
    personalization.add_to(Email.new(email: 'someemail@example.com, name: 'the name'))
    personalization.add_dynamic_template_data('first_name' => 'first')
    personalization.add_dynamic_template_data('last_name' => 'last')
    personalization.add_dynamic_template_data('sender_name' => 'my company')
    personalization.add_dynamic_template_data('sender_address' => 'great street')
    personalization.add_dynamic_template_data('sender_city' => 'some city')
    personalization.add_dynamic_template_data('sender_state' => 'the state')
    personalization.add_dynamic_template_data('sender_zip' => '12345')
    mail.add_personalization(personalization)
    ....
    #<proceed to send email>
childish-sambino commented 4 years ago

@scottbarrow Best I can tell, it's not possible. The design needs to be added to a dynamic template in order to accomplish sending with dynamic template data.