UPDATE: Hi, I still need help with this. Any help would be wonderful.
Hi,
Continuing with my previous posts about triggered emails I decided to go back to send grid.
I have been using a combination of the following templates:
@yisrael-wix 's: https://www.wix.com/corvid/forum/corvid-tips-and-updates/example-send-email-with-the-sendgrid-npm-interface
@code-queen 's: https://support.totallycodable.com/en/article/send-email-notification-using-sendgrid-npm-and-wix-code
I have been able to successfully send the email, but my variables are not coming through.
This is what it looks like on Sendgrid:
This is what it looks like when I receive it:
I was trying what is here that @yoav-wix , @tomer-wix , and @points seemed to solve https://www.wix.com/corvid/forum/community-discussion/jsw-backend-web-module-issues
This is my current code.
Email jsw:
//-------------Imports-------------//
import sgMail from "@sendgrid/mail";
import wixData from 'wix-data';
import {fetch} from 'wix-fetch';
// example sendEmail function from: https://github.com/sendgrid/sendgrid-nodejs/tree/master/packages/mail
const apiKey = "SG.";
//-------------Approve Code-------------//
export function sendEmailapprove (recipient, sender, body, businessName,
member, nonMember, numberOfSpaces) {
sgMail.setApiKey(apiKey);
const msg = {
to: recipient,
from: 'info@sxxxx.com',
templateId:'d-013c14af6fda4a6ea904124e44d61311',
body: JSON.stringify({businessName,member, nonMember, numberOfSpaces})
}
sgMail.send(msg);
}
Page Code: (This is a dynamic page and the email is based on updating the status field)
//-------------Imports-------------//
import wixData from 'wix-data';
import wixLocation from 'wix-location';
import {session} from 'wix-storage';
import wixCrm from 'wix-crm';
import {sendEmailapprove} from 'backend/SHsendEmail';
//-------------Update Code-------------//
$w.onReady(function () {
$w("#dataset1").onReady(() => {
$w("#dataset1").setFieldValue("status", $w("#statusDropdown").value);
$w("#dataset1").save();
});
})
export function submit_click(event) {
//-------------Approval Email-------------//
if ($w('#businessName').validity.valid === false)
return;
if ($w('#email').validity.valid === false)
return;
if ($w('#formIdInput').validity.valid === false)
return;
if ($w('#statusDropdown').validity.valid === false)
return;
if ($w('#statusDropdown') === "APPROVED"); {
sendEmailapprove (
$w('#email').value,
$w('#businessName').value,
$w('#member').value,
$w('#non').value,
$w('#numberOfSpaces').value
)
.then(() => {
let dataObj = {
status: "success",
email: $w('#email').value
};
})
.catch((error) => {
let dataObj = {
status: "fail",
email: $w('#email').value
};
})
}
Things I have tried
- When tired the item.variable (here) shown in @Code Queen Nayeli’s example, nothing happened, and yes, I changed the variables to what is in my dataset.
dynamic_template_data:
{ name: item.title,
email: item.email,
detail: item.detail,
},
};
sgMail.send(msg);
}
When I tried to put “” or ’ around the item. variable it looked like this.
I also tried itemData.Variable and {itemData.Variable}
I also tried itemData.Variable and itemData.Variable
2. I also used this thread by @Tiaan - wix-coders.com:
https://www.wix.com/corvid/forum/community-discussion/sending-template-emails-with-sendgrid-v3
I put in backticks around the variables as suggested by @Roi Bendet as I use them with my non templated email so it seemed logical.
I appreciate any help that you can give me. The sooner the better.
Thank you,
Elizabeth