I want a logged-in Site Member to be able to send a Wix Triggered Email to a client.
Why?
A Company has a client database within a Wix website accessible by Site Members only.
I want to allow a logged in Site Member (employee) to select a client and send that client a triggered email.
The Wix CRM sendEmail() fails if the employee is logged in. But the call to sendEmail() succeeds if the user is logged out.
Try it on this simple site. When you are not logged in, you can send an email to whoever you like; when you’re logged in, you cannot send an email.
peterjanderson6724.wixsite.com/website-3
Any suggestions?
The code behind the ‘Send’ button is:
export function sendEmail_click(event) {
const firstName = 'Test Name';
const lastName = '';
const email = $w('#emailAddress').value;
$w("#message").hide();
let contactInfo = {
"firstName": firstName,
"lastName": lastName,
"emails": [email]
}
wixCRM.createContact(contactInfo)
.then((contactId) => {
console.log('Created contact', firstName, lastName, email, contactId)
let emailOptions = {
"variables": {
"subject": "Test Email"
}
}
wixCRM.emailContact('RLLecSC', contactId, emailOptions)
.then(() => {
console.log("Triggered email sent", email);
$w("#message").text = 'SUCCESS: email sent to '+email;
$w("#message").show();
})
.catch((err) => {
console.log('emailContact FAIL', err);
$w("#message").text = 'emailContact FAIL: ' + err;
$w("#message").show();
});
})
.catch((err) => {
let errorMsg = err;
console.log('createContact FAIL ', firstName, lastName, email, errorMsg);
$w("#message").text = 'createContact FAIL: ' + err;
$w("#message").show();
});
}