Hi , im tryn to import code to make mail from my new Mailjet services here my code but i’m always receiving
TypeError: (0 , u.merciemail) is not a function
but there’s no typo and the import seems ok…
i tried to change the backend rename it , rename the function… nothing work.
if anyone got an idea it would be great
// backend/emailService.web.js
import { fetch } from 'wix-fetch';
export function merciemail(memberEmail, medic, formData) {
const apiKey = 'MYAPI******';
const apiSecret = '**********';
const subject = "got mail - [my site]";
const body = `
<html>
<head>
<style>
body { background-color: black; color: white; }
.highlight { color: #C5D709; font-weight: bold; }
.content-link { color: #C5D709; font-weight: bold; }
</style>
</head>
<body>
<img src="https://static.wixstatic.com/media/5ad5a1_add3c257bece4abaac44ae8c0e07590b~mv2.jpg" alt="Thankc" />
<h2>Bonjour ${medic.prenom},</h2>
<p>Votre compte Thank contient un nouveau remerciement de la part de M. ou Mme ${formData.nommerci} envoyé le ${new Date().toLocaleString()}.</p>
<p class="highlight"><a href="mysite" class="content-link">Cliquez ici pour voir le contenu du message de remerciement.</a></p>
</body>
</html>
`;
const emailData = {
Messages: [
{
From: { Email: 'support@mysite.com', Name: 'Thank' },
To: [{ Email: memberEmail, Name: medic.prenom }],
Subject: subject,
HTMLPart: body,
}
]
};
const emailOptions = {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Basic ' + btoa(`${apiKey}:${apiSecret}`)
},
body: JSON.stringify(emailData)
};
return fetch('https://api.mailjet.com/v3.1/send', emailOptions)
.then(response => response.json())
.then(result => {
if (result.Messages && result.Messages[0].Status === 'success') {
console.log("E-mail ok");
return { success: true }; // Retourne un résultat explicite
} else {
console.error("Error", result);
throw new Error("error");
}
})
.catch(error => {
console.error("Error :", error);
throw error;
});
}
///front end
import wixData from 'wix-data';
import wixLocation from 'wix-location';
import wixStorage from 'wix-storage';
import { merciemail } from 'backend/emailService';
......
const response = await merciemail(medic.email2, medic, formData);
console.log(response.message); // Log
$w("#updateConfirmation").show();
} catch (error) {
console.error("Error :", error);
}
} else {
console.error("no email found.");
}