Hi everyone,
I’m currently working on a Wix website using Velo and trying to send an email through Wix Triggered Emails when a new contact is added to my collection (ContactosLandingGuia
). However, I’m encountering an issue where the email is not being sent, and I’m getting the following error message in the console:
less
Copiar código
Error sending email: Contact [id=5a282ed0-3331-4cd2-81a1-613f71b95cc1] does not have valid email for site [msid=4961f893-febb-4f0b-b38a-b17380a932da]
My current setup:
- I have a backend function (
emailService.jsw
) that is triggered when a new contact is added to the collection. This function is supposed to send a triggered email to the contact. - The contact’s
email
field is correctly inserted into the collection. - I’m using the
triggeredEmails.emailContact
API to send the email based on a triggered email template I set up in Wix.
What I’ve tried so far:
- Ensured the email format is valid: I’ve added validation to check the email format before attempting to send the email.
- Registered the contact in Wix CRM: I suspected the contact might not be properly registered in Wix CRM, so I modified my backend to create the contact using
crm_createContact
before sending the email. - Checked the collection and fields: The
email
field exists in my collection and is populated with a valid email format.
My backend code:
Here’s a simplified version of my code:
javascript
Copiar código
import { crm_createContact } from 'wix-crm-backend';
import { triggeredEmails } from 'wix-triggered-emails-backend';
export async function enviarCorreoAUsuario(email, nombre) {
try {
console.log('Creating contact in CRM...');
let contactResponse = await crm_createContact({
firstName: nombre,
emails: [email],
});
let contactId = contactResponse.contactId;
console.log('Contact successfully created with ID:', contactId);
let emailId = 'triggeredEmailId'; // Triggered Email ID from Wix
// Sending the triggered email
let response = await triggeredEmails.emailContact(emailId, {
contactId: contactId,
variables: {
nombre: nombre
}
});
console.log('Email successfully sent:', response);
return response;
} catch (error) {
console.error('Error sending email:', error);
throw error;
}
}
The issue:
Despite creating the contact and validating the email format, the system still gives me the error saying that the contact doesn’t have a valid email in Wix CRM. I’m not sure if I’m missing a step when registering the contact or if there’s something else wrong in my workflow.
Has anyone encountered this issue before or knows what might be causing it? Any help would be greatly appreciated!
Thanks in advance!