Skip to content
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

Subject not changing in Template mail.send() #713

Closed
falconmick opened this issue Aug 1, 2018 · 27 comments
Closed

Subject not changing in Template mail.send() #713

falconmick opened this issue Aug 1, 2018 · 27 comments
Labels
difficulty: unknown or n/a fix is unknown in difficulty status: help wanted requesting help from the community type: bug bug in the library

Comments

@falconmick
Copy link

Issue Summary

subject not changing in email

Steps to Reproduce

call sgMail.send(seeBellow)

const seeBellow = {
  "from": "bookings@rottnestfastferries.com.au",
  "templateId": "d-1da76d64a1bd4c8b87c035ccaa3f6cfb",
  "dynamicTemplateData": {
    "username": "cvdfd@sharklasers.com",
    "giftcardAmount": "$45",
    "validUntil": "Aug 2019",
    "receiptNumber": 111299,
    "ewayTransactionId": "00003100003509951fac7d25e8dd96e0"
  },
  "personalizations": [
    {
      "to": "cvdfd@sharklasers.com",
      "subject": "Somebody has sent you a Gift Card"
    }
  ],
  "isMultiple": false,
  "substitutionWrappers": [
    "{{",
    "}}"
  ]
}

which results in the following post

{
  "method": "POST",
  "url": "/v3/mail/send",
  "body": {
    "from": {
      "email": "bookings@rottnestfastferries.com.au"
    },
    "personalizations": [
      {
        "to": [
          {
            "email": "cvdfd@sharklasers.com"
          }
        ],
        "subject": "Somebody has sent you a Gift Card",
        "dynamic_template_data": {
          "username": "cvdfd@sharklasers.com",
          "giftcardAmount": "$45",
          "validUntil": "Aug 2019",
          "receiptNumber": 111299,
          "ewayTransactionId": "00003100003509951fac7d25e8dd96e0"
        }
      }
    ],
    "template_id": "d-1da76d64a1bd4c8b87c035ccaa3f6cfb"
  }
}

I have also tried sending 2 emails via an array of messages instead of using personalizations however this also doesn't work.

Finally I have also attempted to place subject beside the from field, still didn't work

Technical details:

  • sendgrid version in lockfile:
    "@sendgrid/mail": {
      "version": "6.3.1",
      "resolved": "https://registry.npmjs.org/@sendgrid/mail/-/mail-6.3.1.tgz",
      "integrity": "sha512-5zIeAV9iU+0hQkrOQ/D4RB2MfpK+lNbOortIfQdCh95aMDF/TRc9WB8FGNhmQrx9YMuJTms5eiBklF0Fi/dbVg==",
      "requires": {
        "@sendgrid/client": "6.3.0",
        "@sendgrid/helpers": "6.3.0"
      }
    },
  • Node.js Version: 8.11.1
@wbw20
Copy link

wbw20 commented Aug 4, 2018

The workaround that I am using is to add a subject in SendGrid's web interface like {{subject}} and then to pass in a subject variable to dynamic_template_data. It seems that template variables work in subjects so you can essentially just pass the entire subject in programmatically that way.

@thinkingserious thinkingserious added type: bug bug in the library status: help wanted requesting help from the community difficulty: unknown or n/a fix is unknown in difficulty labels Aug 4, 2018
@thinkingserious
Copy link
Contributor

Hello @falconmick,

@wbw20 workaround works, please try that as we investigate the root cause.

@wbw20,

Thanks for helping out! I edited out your image because it did not add to the solution. Not sure what your intention was.

With Best Regards,

Elmer

@jeffbax
Copy link

jeffbax commented Nov 8, 2018

FWIW, I see similar behavior with the Ruby lib.

Setting the subject on the email object doesn't carry through to override anything defined on the template on the web tooling. Have to make it a handlebar and add to each personalization.

@tomspeak
Copy link

tomspeak commented Nov 8, 2018

I too am encountering this issue. I am struggling to pin point exactly why it's failing.

@tomspeak
Copy link

tomspeak commented Nov 8, 2018

The workaround seems viable, but is unfortunate as it goes against the set up we have for all other SendGrid e-mails.

@atarabbi
Copy link

atarabbi commented Nov 30, 2018

It should be like:
"dynamic_template_data":{
"subject": "your subject",
},

go to https://sendgrid.com/dynamic_templates
and add {{{subject}}} at TEMPLATE SETTINGS.

It work for me 👍

@thinkingserious
Copy link
Contributor

@atarabbi's solution should be what you need. Please continue to comment on this thread if you still run into issues. Thanks!

@jeffbax
Copy link

jeffbax commented Dec 7, 2018

@atarabbi's solution should be what you need. Please continue to comment on this thread if you still run into issues. Thanks!

But doesn't that still leave things ultimately not working according to how the library API is documented for us to consume? Setting the subject as things allow would still seem broken no?

@baugarten
Copy link

Yeah, the method the docs suggest for changing the subject don't seem to work. I don't know if this is only a problem for dynamic_template_data, but I'm experiencing this as well.

I'll try using a dynamic template for the subject line, but the documentation is surprisingly inconsistent

@aroach
Copy link
Contributor

aroach commented Dec 13, 2018

From what I'm seeing in the docs here, it's documented to update the template subject with the handlebars variable (granted, this could be a more expansive explanation). @baugarten Just to make sure, are you saying that is not working for you? Can you point out where we're pointing you in the wrong direction?

I'm seeing that we're not documenting dynamic_template_data in the client package.

Also, are you using the latest library version v6.3.1?

Definitely want to fix this, and apologize for the confusion!

@SamWheating
Copy link

FWIW I am also seeing this issue in the Golang library, I'm unable to override the template subject from the API call. If I can't find a suitable workaround I'll make an issue there as well.

@sirdodger
Copy link

sirdodger commented May 2, 2019

Ugh, the docs specifically say that the base subject will be overwritten by a personalization subject, which is not at all the same as being able to template the subject.

EDIT: Especially when your own libraries don't work. They add subject in a personalization, where it cannot be used to template. If you expect this to be the documented behavior, then the libraries need to add it to the dynamic_template_data sub-object.

@adamreisnz
Copy link
Contributor

adamreisnz commented Jul 19, 2019

Also ran into this, subject doesn't seem to be overwritten, but work around is usable.

@nielsvhb
Copy link

nielsvhb commented Sep 9, 2019

Leaving the subject in the 'dynamic_template_data' and referring to it in the template with {{{subject}}} does indeed seem to work. Also what I noticed is that custom_args no longer exists. It is merged along with substitutions into 'dynamic_template_data'. Unfortunately the docs don't tell this. If you want to pass a language parameter for example, also do this in your 'dynamic_template_data'.

@deepai-org
Copy link

The "dynamic_template_data" field works but seems undocumented: https://sendgrid.com/docs/API_Reference/Web_API_v3/Mail/index.html

@vladkosarev
Copy link

This is still an issue. Why was this closed?

The workaround does not work reliably. If I send ~30 emails in a loop using the same exact Subject I get some with the subject I sent in and some with (no subject).

Is there currently a way to reliably send in custom subject through the API?

@childish-sambino
Copy link
Contributor

@deepai-org Best to use the latest docs here: https://sendgrid.com/docs/API_Reference/api_v3.html

@vladkosarev Are you saying that you're using the same dynamic template with subject templatized with handlebars (see #713 (comment)) and your request payload contains the proper dynamic template data for the subject and it's not reliably using the subject? If this is the case, best to contact support as this is not something that can/should be addressed by a client-side library.

@vladkosarev
Copy link

@childish-sambino After a while the subject was actually correct in all emails. It seems like there's something async going on for a while and some emails will get old email template and some new.

Is this https://sendgrid.com/docs/API_Reference/api_v3.html correct documentation? I'm pretty sure sending subject as described in that doc does not work. The only way so far that it did work was the workaround described in this ticket.

@childish-sambino
Copy link
Contributor

@vladkosarev Those are the correct docs. If you're using dynamic templates, the subject must be templatized and passed as dynamic template data in order to modify it per-email, as outlined in this issue. If you're not using templates, then the subject provided in the mail-send payload will be used.

As to why some sync was needed in order for the subject to be correct for all emails, best to contact support.

@vladkosarev
Copy link

@childish-sambino Can you please point me where in the docs it explains how to use subject in dynamic template? I still can't find that anywhere in that new link. Thanks!

@aroach
Copy link
Contributor

aroach commented Sep 21, 2020

if I recall correctly @vladkosarev, you want to set the handlebars value in the template itself for the subject -- this is done using the template GUI. Then just reference that value in your code.

image

@vladkosarev
Copy link

@aroach thanks but I'm interested in seeing that in the doc, not in a comment on github. By the way {{}} did not work for me when I tried, only triple brackets {{{}}} worked (could be same async issue as before).

@aroach
Copy link
Contributor

aroach commented Sep 21, 2020

@vladkosarev It appears to be mentioned here: https://sendgrid.com/docs/ui/sending-email/how-to-send-an-email-with-dynamic-transactional-templates/

This Handlebars templating can be used in the text, html, and subject lines of your template.

@vladkosarev
Copy link

@aroach thank you. I just did more tests and subject takes a while to actually 'apply' to a template so it looks like it's not working if you are testing (edit template/send). If you wait 10 min then it actually does get applied and works as intended. I might reach out to SG to document that template updates are not real time (at least for subject) and that you have to wait a bit to do a test. Thank you.

@aroach
Copy link
Contributor

aroach commented Sep 21, 2020

@Whatthefoxsays should be able to chase this down and/or make the appropriate edits. 👋

@vladkosarev
Copy link

@aroach one thing I should probably mention is that we do have two IPs for sending out email. I don't know the inner working of SG but that could be why there's an issue (takes time to propagate to second node?).

@gregonarash
Copy link

@thinkingserious @Whatthefoxsays @aroach

Amazing that 2+ years later the most basic function in email API does not work.... you add subject in JSON and it does nothing.

using the dynamic template as a workaround works fine, but there is obvious bug vs expected behaviour and Senggrid is just sitting on it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
difficulty: unknown or n/a fix is unknown in difficulty status: help wanted requesting help from the community type: bug bug in the library
Projects
None yet
Development

No branches or pull requests