sendgrid / sendgrid-nodejs

The Official Twilio SendGrid Led, Community Driven Node.js API Library
https://sendgrid.com
MIT License
3k stars 780 forks source link

Unsubscribe links in dynamic template are plain text #1107

Closed campgurus closed 4 years ago

campgurus commented 4 years ago

Issue Summary

I m using SG's dynamic template feature to send transactional emails in Node/Express. Everything works fin except that instead of including working links, the footer simply prints "Unsubscribe - Unsubscribe Preferences" as plain text which is not clickable.

I have attempted to use Subscription Tracking, which provides a working link for global unsubscribes, but does not allow me to us the subscription groups I set up.

Here is my code for sending mail:

if (process.env.NODE_ENV === 'production') {
    for (let i = 0; i < recipients.length; i++) {
      const msg = {
        from: "dariusgoore@gmail.com",
        template_id: process.env.SENDGRID_NEW_POST,
        personalizations: [{
            to: { email: recipients[i].email },
            dynamic_template_data: {
                subject: "New Post: " + poster.username + " just posted something",
                recipient_name: recipients[i].username, 
                poster_name: poster.username,
                group_name: group.name,
                post_text: newPost.post.body,
                button_url: process.env.VUE_HOME_URL,
            },
        }],

      };
      let sendResult = sgMail.send(msg);
    }
  }

Technical details:

childish-sambino commented 4 years ago

I'm not seeing a group ID in your message. Can you try adding the unsubscribe group ID? Example:

const msg {
    ...
    asm: {
        groupId: 12345
    },
    ...
};
campgurus commented 4 years ago

Ok that works. Thanks very much. Is that somewhere in the documentation that I simply missed?

childish-sambino commented 4 years ago

There's a little info about the asm param here: https://sendgrid.com/docs/API_Reference/Web_API_v3/Mail/index.html

campgurus commented 4 years ago

Ok. I am surprised you don't get more questions about that. Maybe I am the only one though. Thanks for your help.

On Fri, May 1, 2020 at 10:51 AM childish-sambino notifications@github.com wrote:

There's a little info about the asm param here: https://sendgrid.com/docs/API_Reference/Web_API_v3/Mail/index.html

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/sendgrid/sendgrid-nodejs/issues/1107#issuecomment-622419152, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAJTY42NRPYKRDP5OJZXDI3RPLOX7ANCNFSM4MST32MQ .

JimLynchCodes commented 4 years ago

Just to clarify... what is the secret?

I've added

asm: {
        groupId: 12345
    },

into the msg object, but I'm getting the same behavior as OP- it adds un-stylable links to the bottom of my email when really I would like them to be centered and have a different background color.

@childish-sambino is this possible?

JimLynchCodes commented 4 years ago

actually now that I read it again it seems that OP hd a different issue. His "Unsubscribe" text is not clickable whereas mine is...

renschler commented 3 years ago

Hmm not sure this should have been closed. Also ran into this, the docs should really clarify how to get the unsubscribe module to work in dynamic templates.

abhayciitizen commented 3 years ago

I am also facing the same issue see my cURL below

curl -X POST \
  https://api.sendgrid.com/v3/mail/send \
  -H 'authorization: Key' \
  -H 'cache-control: no-cache' \
  -H 'content-type: application/json' \
  -d '{
  "personalizations": [
    {
      "to": [
        {
          "email": "to email",
          "name": "John Doe"
        }
      ],
      "dynamic_template_data": {
        "name": "John Doe",
        "email": "abc@gmail.com",
        "message":"Testing something"
      },
      "subject": "Hello, World!",
      "asm": {
        "groupId": 16198
    }
    }
  ],
  "from": {
    "email": "as88425@gmail.com",
    "name": "Abhay Singh"
  },
  "reply_to": {
    "email": "noreply@johndoe.com",
    "name": "John Doe"
  },
  "template_id": "template id"
}'

i have created unsubscribe group and pass the group id still not working

clayjones94 commented 3 years ago

@abhayciitizen Try putting asm in the root directory of your POST body

{
    "personalizations": [
        {
            "to": [
                {
                    "email": "to email",
                    "name": "John Doe"
                }
            ],
            "dynamic_template_data": {
                "name": "John Doe",
                "email": "abc@gmail.com",
                "message": "Testing something"
            },
            "subject": "Hello, World!"
        }
    ],
    "asm": {
        "groupId": 16198
    },
    "from": {
        "email": "as88425@gmail.com",
        "name": "Abhay Singh"
    },
    "reply_to": {
        "email": "noreply@johndoe.com",
        "name": "John Doe"
    },
    "template_id": "template id"
}