Send a personnalized mail

Question:
hello everyone,

I would like, with the help of a “Send email” button, to send a personalized email to the user who is connected.
I don’t want to use WIX automation.
On my page I have all the elements I need (Customer name, Email, Total, order details, order number etc)…
I would like it to retrieve these informations and send an email automatically to the customer.
Is this possible by wix code?

Thank you for your help

Product:
Wix editor

What are you trying to achieve:
Send a personnalized mail

Hi, user3373 !!

I think it’s possible. For now, please refer to the link below to get an overview. Also, keep in mind that you’re not necessarily limited to using Wix’s API for sending emails. Using a third-party API specifically designed for email sending can sometimes offer faster and more reliable email delivery. So, there’s also the option to set up an email sending system from your Wix site with those APIs. If you have the budget and are willing to learn how to use them, this option might be better in the long run. Of course, Wix’s email sending API isn’t bad by any means, but since Wix isn’t a company specializing in email services, its performance may be slightly less robust compared to APIs from dedicated email providers. :raised_hands:
For purposes that involve sending a large volume of emails at once, a third-party API would be a better choice. :thinking:

https://dev.wix.com/docs/velo/api-reference/wix-crm-backend/triggered-emails/email-contact

Thank you.

here what i did :

import { Permissions, webMethod } from “wix-web-module”;
import { triggeredEmails } from “wix-crm-backend”;

export const myEmailContactFunction = webMethod(
Permissions.Anyone,
(emailId, contactId) => {
return triggeredEmails
.emailContact(emailId, contactId)
.then(() => {
console.log(“Email was sent to contact”);
})
.catch((error) => {
console.error(error);
});
},
);
$w(‘#EnvoiMail’).onClick(myEmailContactFunction)

just 2 questions : where do i find the “wix-web-module” and “wix-crm-backend” please (
i don’t have these modules in my backend.

Do i have to paste this in my backend directly?

Thanks

Just to confirm, the file where you wrote the code, is it located in the backend? Is the file named something like ○○○○.web.js? You need to create a file in the backend with the code to send an email from the backend (server-side) and give it a name like ○○○○.web.js. Then, you should import this file into the frontend and execute it within the button click event in the frontend. Button click events, for example, need to be written on the frontend. The frontend refers to the section with the $w.onReady() callback. It seems that in your code, some of the backend code may have been written on the frontend, which is likely the mistake. On the other hand, the code related to the button click event should be written in the frontend, like so:

import { myEmailContactFunction } from "backend/○○○○.web.js";

$w.onReady(()=>{

    const emailId = "someEmailId";
    const contactId = "someContactId";

    $w('#EnvoiMail').onClick(()=>myEmailContactFunction(emailId,contactId));

});

Ah Ok! Thanks
Yes, the file is in the backend now. no error and called :“envoimail.web.js”
My button : BtnEnvoimail
Ok for the id of the contact , but where is the id of the mail?

import { myEmailContactFunction } from “backend/Envoimail.web.js”;

$w.onReady(()=>{

const emailId = "???????"
const contactId = "xxxxxxx"

$w('#BtnEnvoimail').onClick(myEmailContactFunction(emailId,contactId));

});

And then i got this error :

ireporters.js:5 Wix code SDK error: The onClick parameter that is passed to the onClick method cannot be set to the value [object Promise]. It must be of type function.

Please check the email ID in the Automation > Triggered Emails section. You should be able to find the email ID for each email there. Also, regarding the error you encountered, it’s my mistake. :melting_face: Please make the following corrections. :raised_hands:

$w('#EnvoiMail').onClick(()=>{
    myEmailContactFunction(emailId,contactId);
});

Have you created a triggered email in wix dashboard?
You can add variables such as (contactId, name or others fetched from collections) into the triggered email. It’s sending rate is average and not too slow. Also, use jsw instead of js to secure the data and pass the frontend data to backend then send the triggered email!

1 Like

Thanks . That is what i did : it’ OK

1 Like