Sendgrid and a strange issue

Hi Guys,

I had created a templated email on sendgrid, which was functioning correctly. Suddenly, the email received is a “plain text” email instead of the usual template. I tried to look for a cause, but havent been able to solve it.

But when i hover my cursor above “body01” in code… it says “dataset9” is not a valid selector.
To my surprise, this dataset9 does not exist on the page where this code belongs. I have only 1 such sendgrid code on 1 page on my site and nowhere else anything. But it is saying dataset9 is not a valid selector.

For a little background. The email is triggered when someone inputs information into a custom form. On button click, a email is triggered via sendgrid. Now all of this has nothing to do with database since all information is passed directly to database via code.

Kindly any clues?

Check what’s this “dataset9 is not a valid selector” that you have in your screenshot.

I checked, I cannot find any dataset9.

@info38197 I don’t know. Maybe it’s something on SendGrid side. Check the template id, and check the template itself.

Also, check how you are coding the page code too as it seems that you using ‘body01’ is causing issues with it as it should just be written as just body otherwise the code will think that it is something else as like your current issue.

The same with your dynamic template data, make sure that it is the correct template id and the handler substitutions in the request JSON are correct to.

Have a look at using Wix Package Manager and the SendGrid nodeJS from there too with this example from Wix.
https://www.wix.com/corvid/forum/community-discussion/example-send-email-with-the-sendgrid-npm-interface

sendEmail.jsw

import sgMail from "@sendgrid/mail";

// example sendEmail function from: https://github.com/sendgrid/sendgrid-nodejs/tree/master/packages/mail

const apiKey = "Sendgrid API key";

export function sendEmail(recipient, subject, sender, body) {
sgMail.setApiKey(apiKey);
const msg = {
to: recipient,
from: sender,
subject: subject,
text: body,
};
sgMail.send(msg);
}

You can find more about the Sendgrid nodeJS by looking at SendGrid’s own docs here.

https://sendgrid.api-docs.io/v3.0/mail-send/v3-mail-send

Nayeli (Code Queen) has an existing tutorial about sending email with the SendGrid nodeJS here.
https://support.totallycodable.com/en/article/send-email-notification-using-sendgrid-npm-and-wix-code

Also, check Vorbly’s tutorial here too for html.
https://www.vorbly.com/Vorbly-Code/WIX-SENDGRID-API-V3---AUTO-EMAIL-MESSAGES

Hey GOS, thanks a lot for all the resources. However my sendgrid email was functioning all right. I was receiving the email in the template i had designed. But suddenly it started sending “ONLY TEXT”. I checked all setting and everything…

I saw just one such post , where a person was complaining same.

https://stackoverflow.com/questions/33906562/sendgrid-always-sends-text-email

Here it suggest .setHtml property, however, How to use it in my code below??

import sgMail from “@sendgrid/mail”;

const apiKey = “API KEY”;
export function emailAdmin(data) {
sgMail.setApiKey(apiKey);
const msg = {
to: “email@xxx.com”,
from : “email@xxx.com”,
subject: “emailAdmin”,
text: ‘body’,
templateId: “ID of my template”,
dynamic_template_data: {
data: data
}
}
sgMail
.send(msg, (error, result) => {
if (error) {
return error;
} else if (result) {
return result
}
});
}