wixCRM.emailContact not always working

Hi there!
Our website uses Wix Code to collect Trial Requests from users and send them the requested trials automatically via triggered emails.
Basically, our code will do the following:
Check if provided form submission email exists on a dedicated DB. This database links email addresses, CRM user ID and an assigned trial product key.
If the user exists, we send email template A, using a wixCRM.emailContact call to the CRM user, and another contact reserved for our sales email. This way bothe our sales and the user itself get an email indicating this email is already registered.
If the User doesn’t exist, we:
- Take a trial PK from another DB
- Create a CRM user
- Insert the CRM, along with the email and assigned PK to the DB
- Send an email to both the user and our sales contact
This setup was working pretty well until recently, where we noticed that trial requests are coming in, getting assigned with a PK and CRM contact ID, inserted to the DB, but no email is sent out to the clients, on a testing session we saw an email address requesting trial and not getting an email (gets PK and new CRM ID well), yet few minutes later, when cleared the tables and run that exact same scenario - it worked!

Are you familiar with any open issues with wixCRM.emailContact? are we doing anything wrong? is there a way to get logs of Backend .jsw functions ? - that would help us debug as it does not reconstruct

We know for a fact that new requests came in as our custom DBs are getting filled with new emails and CRM IDs, and users are redirected to a thank you page - which happens only after firing a wixCRM.emailContact event…

Any information will be helpful as wix support could not assist much over the phone, and this is pretty much critical service for us - we want to avoid integrating a 3rd party email supplier like sendgrid…

Thanks,
Amir.

Just updating,
When waiting for the email to be sent, by then()/catch()-ing the promise, in cases it doesn’t work, i get to following error when sending an email to the fixed salses contact id:
server responded with - {“message”:“Invalid identity”,“details”:{“errorcode”:“-5002”}} (401)

Again, important to say this happens sporadically. So I currently can’t point at the exact scenario it reconstructs.

With no luck getting help from Wix support nor the forum - if you have the above issue or need reliable triggered emails via code - use SendGrid.

Hi,
Please share your code and the site URL so we can inspect.

Thanks,
Or

https://www.mortgagefree.info/copy-of-albany-hill


import wixCrm from ‘wix-crm’;
$w.onReady( function () {
$w(“#nameInput”).value = “Jity Mishra”;
$w(“#phone”).value = “1234567890”;
$w(“#emailInput”).value = “mrinalsworld@gmail.com”;
$w(“#signUpButton”).onClick( () => {
wixCrm.createContact( {
“firstName”: $w(“#nameInput”).value,
“emails”: [$w(“#emailInput”).value],
“phones”: [$w(“#phone”).value]
} )
.then( (contactId) => {
wixCrm.emailContact(‘signUpEmail’, contactId);
});
});
});

Hey guys,

this is still an issue. wixUsers.emailUser works fine but only with the current user. To write an email to another user I need wixCRM.emailContact.

It seem to work since “Was send fine” it printed in the site monitor without any issues but the actual email is not send:

wixCRM.emailContact('assignmentMail', "5b3f2d16-1c90-4157-b4fa-f920ec9fd9ce")
        .then( () => {
          console.log("Was send fine")
        } )
        .catch( (err) => {
          console.log("error: " + err)
        } );

Is there a bug with this module?

Found a workaround using wixCrmBackend to send emails to others then the logged in user:

// Create a backend file: e.g. email_service.jsw
import wixCrmBackend from 'wix-crm-backend';

export function send_email() {
    user_id="YOUR USER ID"

    wixCrmBackend.emailContact("email_ID", user_id, {
        } )
        .then( () => {
            console.log("email send")
        } )
        .catch( (err) => {
            console.log("email broken" + err)
    } );
}

Call this function in one of your front-end pages:

import {send_email} from 'backend/email_service.jsw';
send_email()

Note: Strangely it doesn’t work with the Admin id logging it doesn’t recognize his email. You have to use any other member (like a second account).