Hi everyone again !!
So I figured it out myself … however this is a bit weird … I think my problem might help others so I will try to explain what I did to go around the error.
Apparently, reading the tutorial about sending a triggered email, the solution explained is to use wix-crm and/or wix-users and to develop all the code in the frontend file of your page …
However, it has been recently implemented the same tools to use as backend which should be anyway how to develop it for safety reasons. If you try to send a triggered email using a third party, then you have to develop it with some backend code.
So here is what I did : first create a new web module : I call it “sendEmail.jsw”
And I code it like that :
import wixCRM from 'wix-crm-backend';
import wixUsers from 'wix-users-backend';
export function sendEmail(
from_name_value, emails, coming_status_value,
coming_people_value, message_value){
wixCRM.createContact({
"firstName": from_name_value,
"emails": emails
})
.then(contactId => {
return wixCRM.emailContact('cedricMailId', contactId,
{
variables: {
"from_name": from_name_value,
"coming_status": coming_status_value,
"coming_people": coming_people_value,
"message": message_value
}
})
.then( () => {
// do something after the email was sent
})
.catch((err) => {
// handle the error if the email wasn't sent
console.log(`error : ${err}`);
})
})
}
This creates a function that I will call on my main page code passing as arguments all the informations needed to create my email (you can put as many as you want).
And now on the page where I want my email triggered, I will first import this function and when the form is submit in my case (or in a button event function if you like) I will call composeAndSendEmail()
import {sendEmail} from 'backend/sendEmail.jsw';
$w.onReady(function () {
//TODO: write your page related code here...
$w("#dataset1").onAfterSave( () => {
composeAndSendEmail();})
})
Finally, the last function call is the one doing all the work, getting all the values from the differents input from the dataset and creates the values sent to the backend function sendMail()
export function composeAndSendEmail(){
let from_name_value = $w("#input1").value;
let email = $w("#input2").value;
let coming_status_value = "";
let coming_people_value = "";
let message_value = "";
let emails = [email];
// I removed my long code processing the data from the user
//call the backend function with the data processed
sendEmail(from_name_value,emails,coming_status_value,coming_people_value,message_value)
.then( () => {
//what to do once the email is sent
})
}
I hope this will help others with the same problem !! I close the topic if I can, if not maybe an admin could do it please. Thanks again.