-
Notifications
You must be signed in to change notification settings - Fork 782
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
Cannot use Substitutions neither in Personalizations nor in Mail objects #433
Comments
Hi @dbaranovsky, I was able to reproduce and I've added this to our backlog for a fix. For now, this example works. Here is the code I used to test: // Setup sendgrid api
const sgMail = require('@sendgrid/mail');
sgMail.setApiKey(process.env.SENDGRID_API_KEY);
sgMail.setSubstitutionWrappers('-', '-'); // Configure the substitution tag wrappers globally
const msg = {
to: 'elmer.thomas@sendgrid.com',
from: 'dx@sendgrid.com',
subject: 'Hello world',
text: 'Hello plain world!',
html: '<p>Hello HTML world!</p>',
templateId: '13b8f94f-bcae-4ec6-b752-70d6cb59f932',
substitutions: {
name: 'Some One',
city: 'Denver',
},
};
sgMail.send(msg); Thanks! With Best Regards, Elmer |
Thoughts on this one? |
I'll have a look! |
PR created to fix this issue |
Having this issue on all subs: trying to sub a form response template with the following:
Into:
Which should yield :
Instead, i get:
Using the latest Node Mail SDK. This only works with the .send method, since using the POST method with postman works fine... Cheers |
Could you please post the entire code you're using to send & construct the email? I can see your configuration and at first glance it looks ok, but I'd like to see the full JS. Are you using @sendgrid/mail and not by any chance the old sendgrid package? |
I'm using sendgrid/mail Turns out that in my test I had a top-level "email" field that I'd forgotten to remove. as in
removing the field fixed the issue and things worked normally. however, re-implementing it still produced the issue. So it's a fix on my end, however just letting you guys know this does happen. The code used is basically your example in your Readme for template usage, whereas:
Produces the error and this:
Does not. Thanks for the reply either way! |
Right, email shouldn't be there!
…On Wed, Feb 14, 2018, 06:26 murphman300 ***@***.***> wrote:
I'm using sendgrid/mail
Turns out that in my test I had a top-level "email" field that I'd
forgotten to remove.
as in
***@***.***", ...the rest of the object...}
removing the field fixed the issue and things worked normally. however,
re-implementing it still produced the issue. So it's a fix on my end,
however just letting you guys know this does happen.
The code used is basically your example in your Readme for template usage,
whereas:
// Setup sendgrid api
const sgMail = ***@***.***/mail');
sgMail.setApiKey(process.env.SENDGRID_API_KEY);
sgMail.setSubstitutionWrappers('-', '-'); // Configure the substitution tag wrappers globally
const msg = {
email: ***@***.***',
to: ***@***.***',
from: ***@***.***',
subject: 'Hello world',
text: 'Hello plain world!',
html: '<p>Hello HTML world!</p>',
templateId: '13b8f94f-bcae-4ec6-b752-70d6cb59f932',
substitutions: {
name: 'Some One',
city: 'Denver',
},
};
sgMail.send(msg);
Produces the error and this:
// Setup sendgrid api
const sgMail = ***@***.***/mail');
sgMail.setApiKey(process.env.SENDGRID_API_KEY);
sgMail.setSubstitutionWrappers('-', '-'); // Configure the substitution tag wrappers globally
const msg = {
to: ***@***.***',
from: ***@***.***',
subject: 'Hello world',
text: 'Hello plain world!',
html: '<p>Hello HTML world!</p>',
templateId: '13b8f94f-bcae-4ec6-b752-70d6cb59f932',
substitutions: {
name: 'Some One',
city: 'Denver',
},
};
sgMail.send(msg);
Does not.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#433 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAd8Qgev1QXQvqueU4uLZBxMahM37-a3ks5tUcXPgaJpZM4PGk_I>
.
|
Thanks @murphman300 for the follow up and @adamreisnz for the confirmation! |
Issue Summary
I'm receiving the following error:
If don't use personalizations (and use Substitutions in the root object), then email is sent fine, but Substitutions are not replaced, because @sendgrid/helpers/classes/Mail object in its toJSON method ignores 'substitutions' property.
Technical details:
The text was updated successfully, but these errors were encountered: