Hi Wix team,
I have asked this question before but I’ve heard there has been a change to the API for allowing people to email users who aren’t logged in? I have played with the code below but have hit a stumbling block, no errors and the data seems to come from the backend but the variable triggered email doesn’t send.
Backend
import wixUsers from 'wix-users-backend';
export function sendEmailtoOwnAddress() {
wixData.query("CourseAvailability")
let id = "2a4f5fb7-5027-41e9-8d9c-8ef1a368d098" //my own Id for the business account
.eq("_owner", id)
.find()
.then((results) => {
let item = results.items[0];
let userId = item._owner
let value1 = item.fullName;
let value2 = item.title;
let value3 = item.totalPrice;
let value4 = item.outstandingBalance;
wixUsers.emailUser('outstandingBalanceTemplate', userId, {
variables: {
name: value1,
courseTitle: value2,
totalPrice: value3,
outstandingBalance: value4,
}
})
.then(() => {
console.log("Email sent!")
})
.catch((err) => {
console.log("Error!")
});
console.log(userId)
console.log(value1)
console.log(value2)
console.log(value3)
console.log(value4)
console.log(item)
})
}
Frontend
import wixUsers from 'wix-users';
import wixUsersBackend from 'wix-users-backend';
import {sendEmailtoOwnAddress} from 'backend/utilitiesModule'
if (wixUsers.currentUser.loggedIn) {
const userId = wixUsers.currentUser.id;
let value1 = fullName;
let value2 = totalPrice;
let value3 = paidToday;
let value4 = courseTitle;
let value5 = dateFormatted;
wixUsers.emailUser("paymentCompleteEmail", userId, {
variables: {
"name": value1,
"totalPrice": value2,
"paidToday": value3,
"courseTitle": value4,
"paymentDate": value5,
}
})
.then(() => {
console.log("Triggered email sent");
sendEmailtoOwnAddress()// backend function
})
.catch((err) => {
console.log(err);
});
}
The code above works on it own and sends the triggered email to the logged in user but doesn’t trigger or implement the backend function to send the email to me. i have read every document I can find in the past 36 hours of trying but to no avail.
Any help would be much appreciated after way too much time trying to figure this out…
Thank you