What is wrong with my triggered mail? (Solved)

Yeah, I’m trying to send a triggered mail when someone logged in succesful like a 2fa but it does not work. I do not get any errors in the text field.This is the code I made:

export function button7_click(event, $w) {
const ID = wixUsers.currentUser.id
wixUsers.emailUser(‘2fa’, ID, {
variables: {
fa: faPassword
}}).then( () => {
$w(‘#text18’).text = “Waiting for 2fa e-mail confirmation”;
} )
.catch( (err) => {
$w(‘#text18’).text = err;
} );

There is a } missing at the end but I guess that’s a paste problem. I would console log the ID to check you get the users id and also make sure the 2fa is really a correct Wix Triggered Email Code. I can’t see where you define the variable faPassword so make sure that is defined because you can’t send an undefined variable to a user.

export function button7_click(event, $w) {
 const ID = wixUsers.currentUser.id
 console.log("User ID holds the value of: " + ID);
 wixUsers.emailUser('2fa', ID, {
 variables: {
 fa: faPassword
        }
        }).then( () => {
 $w('#text18').text = "Waiting for 2fa e-mail confirmation";
        } )
        .catch( (err) => {
 $w('#text18').text = err.toString();
        } );
    }


Hope it helps!

1 Like

Yes, the } was a pasting problem. I’m sure that 2fa is a correct user ID (I just checked). FA password is defined like this:
let faPassword = makeid();

And makeid(); is like this:

function makeid() {
var text = “”;
var possible = “ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789”;

for ( var i = 0; i < 5; i++)
text += possible.charAt(Math.floor(Math.random() * possible.length));

return text;
}

And this is what I use to define the users ID:

const ID = wixUsers.currentUser.id

Found out what was wrong. Apparently I can’t send an email to my own email with wix or something? Like if I have myself as a contact I can’t use triggered emails on my self. Well thanks for the help :slight_smile:

1 Like