Hi,
I wrote a code that sends email to users, but the problem is that its sending the email only to the logged-in user.
I want to loop throgh all my users and get their Id so I can use my sending email function.
my code looks like this:
import { triggeredEmails } from 'wix-crm';
import wixUsers from 'wix-users';
$w.onReady(function () {
$w('#testButton').onClick( () => {
let user = wixUsers.currentUser;
wixUsers.currentUser.getRoles().then((roles) =>
{
for (let i = 0 ; i < roles.length ; i++) {
if (roles[i].name == 'Experiment no video' || roles[i].name == 'Experiment with video' ) {
triggeredEmails.emailContact('Contact', user.).then(() => {
console.log('Email was sent to contact');
})
.catch((error) => {
console.error(error);
});
}
if(i==roles.length)break;
}
})
});
});