Closed nyel-gh closed 5 years ago
Same as #834
@10kc-zack I see. It is a known issue then.
By the way, what workaround did you do to fix it?
@nyel-dev Setting the template's subject on SendGrid website works. The problem is that it seems that SendGrid's API does not let you supply a template when you trigger a dynamic template.
Hello @nyel-dev,
I believe in the transactional template you would set the subject to be {{ subject }}, then in your code you set data.subject
to be "[TEST] My Email Subject"
.
Does that work for you?
With Best Regards,
Elmer
Hi @thinkingserious, hoping you may have additional insight.
I am transitioning from a legacy template to the transactional template and I am experiencing this same issue now (sendgrid-nodejs v6.3.1, Node: v8.11.4) even after replacing the transactional template subject field with {{subject}}
. I have not explicitly set the substitution wrappers via setSubstitutionWrappers()
and have just fallen back on the default handlebars set (although I did try setting those as well while testing).
I've confirmed I'm passing a subject
property (no quotes or special characters) as msg.subject
in my first test case, msg.dynamic_template_data.subject
in my second test case and with both set for my third test case and the resultant emails received still do not have the subject replaced as I would expect. The email subject shows "(no subject)".
Testing the template itself on the sendgrid site in Preview mode and setting the Test Data, does replace the text as expected though.
Any help would be appreciated. Thanks!
EDIT I should also mention that substitutions in the body of the message get replaced as expected, just not in the subject line.
@thinkingserious the subject not show in email same with example
to: "email@example.com",
from: "email@example.com",
subject: "Hello world",
text: "Hello plain world!",
html: "<p>Hello HTML world!</p>",
templateId: "d-xxxx",
dynamic_template_data: {
subject: "Testing Templates & Stuff",
name: 'Some "Testing" One',
city: "<b>Denver<b>"
}
Hello @jlouie,
Here is a complete example. I hope that helps!
With Best Regards,
Elmer
@thinkingserious: Unfortunately, it doesn't. I'm still experiencing a missing Subject line in the email sent/received, just like @nicholasess.
Hello @jlouie,
Does your subject area look something like this in the UI?
With Best Regards,
Elmer
By the way I was able to solve this problem by using the Set Subject on the Sendgrid template interface. Thanks @thinkingserious
I suggest that the settings change to the menu like code, test data.
The place where is the settings, is hidden :/
Thanks for the feedback @nicholasess! I will pass it on to the design team.
I ran into the same problem, and I had to rely on this workaround, but it would not have worked without sifting through issues.
This is super counterintuitive, as the doc says that you set the subject in the API call (and details how you can set it globally for the message and override it in personalizations, which is obviously lost with this workaround).
We also lose the "default subject set on the admin page, which can be overridden in the API call" feature. Nope, with the workaround we always have to specify a subject for the affected templates.
(Unless there's a way to set default in {{ }} interpolation. I'll check the doc for that, what I've found so far is about an interpolation method using dashes, which I'm completely unfamiliar with.)
@thinkingserious
Why is this issue closed? It is not fixed.
I know it might looks weird, but guys make sure you don't have opened windows or tabs with the same screen. Sendgrid ui has autosave which can rewrite all data which you saved before.
use in subjects {{subject}}
and send as variable like other variables ,
this way it work .
I was stuck on this issue for so long because I was following the docs and thought I did something wrong. Since I'm migrating from legacy templates, I thought the API would stay the same and I was surprised to see it suddenly not work as expected.
Are there any plans to update the documentation to v3/mail/send
to properly reflect this change?
The only way I was able to solve this issue was with triple-stash:
{{{ subject }}}
According to this article https://github.com/sendgrid/sendgrid-nodejs/blob/master/use-cases/transactional-templates.md
Can confirm using triple instead of double curly braces in the subject field works
Whenever I save the triple curlys or any other code in the subject line, the code reverts back automatically after a few minutes to the standard <%subject%>.
Is anyone else having the same issue?
Is anyone else having the same issue?
I have seen something like this when I had two windows open. SendGrid auto-saves, so if you have two windows open, they will cancel each other out.
The way it worked for me:
use in subject field in SendGrid UI: {{{subject}}}
send "subject": "test"
in message.dynamic_template_data
Suggestion: You guys should really work on your docs. I mean really they are so scattered and bits and pieces are outdated.
Triple brackets is still working, I'm just checking to see if that is still the official solution.
Thanks!
@tcukanoot Yes.
Please do re-open issue! The documents still are not correct suggesting subject
to be set on the top level of the request. However, it must be included in dynamic_template_data
and subject in template must be set as {{subject}}
or any other dynamic key. This is open from 2018 and no any changes in documentation introduced since!
I get a 400 request error from the server when I'm trying to use substitutions or dynamic_template_data
Please fix your docs. dynamic_template_date shouldn't be valid based on the https://github.com/sendgrid/sendgrid-python/blob/main/use_cases/kitchen_sink.md and the v3 documentation Yet people are reporting that it works for them
what's going on? 🤔
The way it worked for me:
use in subject field in SendGrid UI:
{{{subject}}}
send
"subject": "test"
inmessage.dynamic_template_data
Suggestion: You guys should really work on your docs. I mean really they are so scattered and bits and pieces are outdated.
How to do it in PHP. Please share the code!
Are the docs currently just incorrect in suggesting that subject be sent as a top level parameter then?
The way it worked for me:
use in subject field in SendGrid UI:
{{{subject}}}
send
"subject": "test"
inmessage.dynamic_template_data
Suggestion: You guys should really work on your docs. I mean really they are so scattered and bits and pieces are outdated.
This worked for me! Your doc should look something like:
const msg = {
to: toEmail,
from: "email",
templateId: "tempateId",
dynamic_template_data: {
subject: "subjectHere",
},
};
sendGridEmail
.send(msg)
.then(() => console.log("email sent"))
.catch((error) => console.error(error.toString()))
When i used triple bracket i was still missing the fact that subject property must be placed under dynamic_template_data and not at higher level as wrongly stated in docs
Is there any way to put variable in mail subject ?
The way it worked for me: use in subject field in SendGrid UI:
{{{subject}}}
send"subject": "test"
inmessage.dynamic_template_data
Suggestion: You guys should really work on your docs. I mean really they are so scattered and bits and pieces are outdated.This worked for me! Your doc should look something like:
const msg = { to: toEmail, from: "email", templateId: "tempateId", dynamic_template_data: { subject: "subjectHere", }, }; sendGridEmail .send(msg) .then(() => console.log("email sent")) .catch((error) => console.error(error.toString()))
this works with {{{subject}}} in template in sengrid web
November 2021, still not working according to the documents
I notice the subject always use the dynamic template setting from official
message = Mail( from_email=FROM_EMAIL, to_emails=TO_EMAILS, subject='a test subject' )
The param "subject" in above code is not working
For me when using {{subject}} on the template page in the subject field, then setting:
mail.getPersonalization().get(0).addDynamicTemplateData("subject", "MyCoolSubject");
Worked
Thanks! I have solved the problem
On Fri, Dec 17, 2021 at 8:50 PM Attila Novák @.***> wrote:
For me when using {{subject}} on the template page in the subject field, then setting:
mail.getPersonalization().get(0).addDynamicTemplateData("subject", "MyCoolSubject");
Worked
— Reply to this email directly, view it on GitHub https://github.com/sendgrid/sendgrid-nodejs/issues/843#issuecomment-996697930, or unsubscribe https://github.com/notifications/unsubscribe-auth/AWU3J4LCXUTH4GJGKFOZXVTURMWXVANCNFSM4GCHRZHQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.
You are receiving this because you commented.Message ID: @.***>
@breakline87 solution solved the problem for me.
{ from: "admin@test.com", template_id: "d-xxx", personalizations: [ { to: [{email: "test@test.com"}], dynamic_template_data: { username: "test", subject: "Hello World", }, }, ], };
I was trying to add subject for my email with dynamic templates but it is not working. Is this a known bug already? Can you suggest any workarounds for this issue?
template code:
send mail function: