sendgrid / sendgrid-ruby

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

Sending many emails to one receiver at once with different dynamic_template_data #415

Closed zhyhun-ivan closed 4 years ago

zhyhun-ivan commented 4 years ago

Issue Summary

I am trying to send multiple emails to one receiver using

SendGrid::API.new(api_key: ENV['SENDGRID_API_KEY'])
  .client._('mail/send').post(request_body: request_body)

request_body looks like:

{
      template_id: id,
      subject: subject,
      from: { email: DEFAULTS_MAPPING[:email], name: DEFAULTS_MAPPING[:name] },
      personalizations: [
        {
          to: "same_email@email.com",
          dynamic_template_data: {
            name: "Name1",
            member_name: "First Member"
        },
        {
          to: "same_email@email.com",
          dynamic_template_data: {
            name: "Name New,
            member_name: "Second Member"
        }
      }
}

Steps to Reproduce

  1. Follow logic from summary

Exception/Log

If it possible to make it work, as i expect to send emails by making one request instead of multiple related only to differences between dynamic_template_data

Technical details:

childish-sambino commented 4 years ago

I think that works fine. Are you seeing any errors?

zhyhun-ivan commented 4 years ago

I have no errors, also i see that both emails are processed through sendrgid panel, but i receive only one email with randomly picked values from one of dynamic_template_data hashes. https://sendgrid.com/docs/for-developers/sending-email/personalizations/ - here i found this Tip:

All of the recipients in a single personalization object (either in the to, cc, or bcc fields) will see the same email, as defined by the data in that personalization, as such we do not allow duplicate emails between these 3 arrays in a single personalization.

But it's not clear if there's any workaround.

childish-sambino commented 4 years ago

Hmm, just tried this and see both emails when using the gmail client but weird stuff when using the Mac mail client (preview shows first email but opening shows second email). Are you seeing similar behaviour with different client?

zhyhun-ivan commented 4 years ago

I tried and have only one email using any client, but i can see that 2 emails were processed and delivered

Screen Shot 2020-04-01 at 10 18 43 PM
zhyhun-ivan commented 4 years ago

After aprox 10 minutes, i received second email, but with dynamic_template_data values from the first one.

childish-sambino commented 4 years ago

Think it's best to open a support ticket to better triage this issue.

thinkingserious commented 4 years ago

Hello @zhyhun-ivan,

Thanks for submitting a GitHub issue! We are very sorry that you are running into this problem. In order to better serve you, as this does not present itself as a library specific issue, we would like to ask that you reach out to our support team at https://support.sendgrid.com.

Thank you!

SendGrid DX Team