Help with Triggered Emails!

Hello!

I created a “social media” site that allows users to visit and post on each other’s profiles. I’d like to incorporate a means of notifying clients when someone has filled out a custom form on their page. As a result, I tried to use a triggered email. Here’s the code that I used.

let url = wixLocation.url;
getHostID(url).then(hostID =>{
wixUsers.emailUser(“emailID”/actual ID subbed here/, hostID)
.then( () => {
console.log(“Triggered email sent. Hooray!!”);
} )
. catch ( (err) => {
console.log(err);
} );
})

However, when I run it, I get the following error message:

contactId does not match current session contact (401)

It’s true. The contact ID won’t match the current session ID, because I want the host page owner to be notified, not the current user. Is there any way to get around this?

I’ve been working with Wix Code/Corvid for a few months now, but still have a lot to learn. I would really REALLY appreciate any help that could be offered.

Thanks!

@moreganocarr are you using wix user or wix user backend. Because for the wix-user (frontend) there is the following restrictions

You can only send the email to the currently logged-in member. You can get that member’s ID using the id property of the currentUser .
But I’m not even sure if that restriction does not apply to wix-user-backend as well. You have to try (plz share your results :slight_smile: ) .

A workaround is to use a mail service provider to send your email via code :slight_smile:

Hi! Yes, I tried both front-end and back-end and got the same result.

I think I’ll try using Nodemailer next. Perhaps that will work for me. Thanks so much!

I tried the Nodemailer npm. It works perfectly! Thanks again.

I’m sorry. Typing too fast. I tried Nodemailer package.