New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Substitution not working if the substituted data is huge #508

Open
ghost opened this Issue Oct 18, 2017 · 4 comments

Comments

Projects
None yet
3 participants
@ghost
Copy link

ghost commented Oct 18, 2017

Substitution not working if the substituted data is huge

I am trying to send SendMultipleEmailsToMultipleRecipients to send multiple emails to multiple recipients in batch. I don't want to personalize the email content through sendGrid's personalization since there is an in-house custom personalization process and I want to use Substitution to replace a template string ({content}) with the personalized email content. The problem is that I get badRequest once I post it.

Here is my code:

var tos = new List<SG.Helpers.Mail.EmailAddress>();
var subjects = new List<string>();
var substitutions = new List<Dictionary<string, string>>();

foreach (var message in emailMessages)
{
	tos.Add(new SG.Helpers.Mail.EmailAddress(message.To.Single(), message.ToName.Single()));
	subjects.Add(message.Subject);
	substitutions.Add(
		new Dictionary<string, string>() { { "{content}", message.Body } }
	);
}

var msg = SG.Helpers.Mail.MailHelper.CreateMultipleEmailsToMultipleRecipients(
	new SG.Helpers.Mail.EmailAddress(senderEmail, senderName),
	tos,
	subjects,
	"{content}",
	"{content}",
	substitutions
);

If I replace message.Body with let's say, message.ToName.Single(), the batch emails goes through successfully.

Not sure what's causing the problem or how I can approach this use-case.

Technical details:

  • sendgrid Version: v3 (latest)

@ghost ghost changed the title Substitution not working if the data is huge Substitution not working if the substituted data is huge Oct 18, 2017

@mbernier

This comment has been minimized.

Copy link
Contributor

mbernier commented Oct 19, 2017

There is an API limitation of 10,000 bytes for the substitutions object. Is it possible you are going past this limit?

Also, can you please share the error string the API gives back to the library?

@mbernier

This comment has been minimized.

Copy link
Contributor

mbernier commented Oct 24, 2017

Oops, didn't mean to close this!

@ghost

This comment has been minimized.

Copy link

ghost commented Oct 25, 2017

@DrMeloMoney

This comment has been minimized.

Copy link

DrMeloMoney commented Mar 20, 2018

Hi @Sanichita,

I'm really sorry that we've taken so long to get back to you.

The best way to get around the limitation for Substitutions is to use Section Tags. Below is a link to our docs and let me know if you have other questions!

https://sendgrid.com/docs/API_Reference/SMTP_API/section_tags.html https://github.com/sendgrid/sendgrid-nodejs/blob/master/packages/helpers/classes/mail.d.ts#L307

Best,
Zach M.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment