node.js sendgrid implemantaion

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



node.js sendgrid implemantaion



I have followed the SendGrid docs in order to create dynamic transactional email.
But for somehow I could not assign the variables. They always returns empty.


const sgMail = require("@sendgrid/mail")
const SENDGRID_API_KEY = "deleted for safety, no worries i fill the right value here"
sgMail.setSubstitutionWrappers("", "")
sgMail.setApiKey(SENDGRID_API_KEY)

const msg =
to: "deleted for safety, no worries i fill the right value here",
from: "deleted for safety, no worries i fill the right value here",
subject: "Hello world",
text: "Hello plain world!",
html: "<p>Hello HTML world!</p>",
templateId: "deleted for safety, no worries i fill the right value here",
substitutions:
name: "Some One",
city: "Denver",
,
;
sgMail.send(msg);



Template:


<html>
<head>
<title></title>
</head>
<body>
Hello name,
<br /><br/>
I'm glad you are trying out the template feature!
<br><br>
I hope you are having a great day in city :)
<br /><br/>
</body>
</html>



Result:



Hello,



I'm glad you are trying out the template feature!



I hope you are having a great day in :)



Api keys are correct and the result is the mail I get. Can you guys tell me what I am missing?





I'm guessing you grabbed this example from here. What I realized in your code is that you have name repeated in the substitutions property of the msg. Not sure if that might be the problem.
– Luis Crespo
Aug 12 at 18:52



name


substitutions


msg





Yes i took it from there, and no it's just a typo. Thank you for pointing out. I've edited it.
– Mücahid Erenler
Aug 12 at 19:14





It's been already answered over here, go and check it out.
– Mücahid Erenler
Aug 12 at 19:20









By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

How to determine optimal route across keyboard