#featurerequest
OK, so I have been trying to do something for WEEKS now. It seems pretty simple, but apparently not.
On a members only page I have generated code to trigger an email to the currently logged in user when they reach a goal in our club. This part of the code works juts fine!
HOWEVER , at the same time (when the member reaches the goal) I want to trigger an email (it can even be the same email!) to our business manager (who is also a member), but not logged in of course. This would seem to be pretty easy, but NO!!! I have been back and forth multiple times with Wix Support and they keep telling me how to send the email to the currently logged in user, NOT a specific user not logged in!!! I finally inserted code to create (update) a user using this snippet (after including import wixCrm from ‘wix-crm’; at the top of the code) :
// Send email to specific user let firstName = “manager”; let lastName = “business”; let email = “manager@business.com”; let contactInfo = { “firstName”: firstName, “lastName”: lastName, “emails”: [email]}; wixCrm.createContact(contactInfo) .then((contactId) => { wixCrm.emailContact(‘Testemail’, contactId)})
This supposedly creates (updates) a contact and returns the contact id. NOPE, doesn’t even create the contact.
If you want to send an email to a member who is not logged in then query the PrivateMembersData database via a backend file , get their contact ID and send the email via the ‘wix-crm-backend’ api . You do need to have the member’s email to query the Members database.
If the email is going to be constant then just hard code it on the backend file.
//backend/doStuff.jsw
import wixCrm from 'wix-crm-backend';
import wixData from 'wix-data';
let options = {
"suppressAuth": true
}
function getCntId(email) {
return wixData.query('Members/PrivateMembersData') //query
.eq('loginEmail', email)
.find(options)
.then( (results) => {
let Item = results.items[0];
let contactId = Item.contactId; //get contact id
return contactId; //return the contact id
});
}
export function sendMail() {
let email = 'youremail@domain.com'; //member email
getCntId(email)
.then( (consumer) => { //contact id received
wixCrm.emailContact('trgEmailId', consumer); //send mail
});
}
Thanks. I’ll study this a bit to be sure I understand how it works. Since I haven’t used the backend api before, I might learn something along the way!
@shantanukumar847 Thanks… While I was waiting I found some of those errors too. BTW: My triggered email ID is ‘Testemail’ :-). I’ll get back to you when I try it again!
@shantanukumar847 Oh heck!!! The email to the specific user was going into the Spam/Junk folder in icloud mail!!! Geeezzz…. Thank you soooooo much! It seems to work!!!
@nino : What I did was develop an Irish Whiskey Club for our restaurant. I documented the entire process and code for my daughter to implement on our live sight. If you provide an email address, I can send you a PDF of the instructions and all the coding.