Emails aren't going out on user signup

I want to use Wix code to send an automated email out to my users when they log in. I’m using the code snippet below, and I’ve console logged my way through it, and everything seems to make sense, but the emails don’t seem to be being sent out:

$w("#dataset1").onAfterSave( () => { 
    wixCRM.createContact( { 
        "emails": [$w("#input2").value] 
    } ) 
    .then( (contactId) => { 
        wixCRM.emailContact("R0q92ZI", contactId, { 
            "variables": {} 
    } ).catch(error => console.log(error)); 

Additional context: I’ve checked my spam folder and haven’t found anything there. No error is being thrown, either, and I’ve confirmed that $w("#input2").value is indeed a correct email address when I test it.

Does anyone have an idea about what might be going on here?

You probably should be using wix-users.

When a user has logged into your site you can use wix-users.currentUser.isLoggedIn to test to see if your visitor is logged in.

If they are then you should be able to use wix-users.emailUser for example:

import wixUsers from 'wix-users';

$w.onReady(() => {
    let thisUser = wixUsers.currentUser;
    if (thisUser.isLoggedIn) {

Now if you are using wixUsers.promptLogin() or wixUsers.login() you can perform this email action in a .then() call since both of these return promises that execute after the login completes.

Hope this helps

Hi Jeremie,

wixCRM.emailContact does not work in the preview. It only works on a live site.

Yes good point Yevhen.

Jeremie how are you testing this out? Does the problem go away on your published site?