Send email to NOT logged in member!

#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.

Surely, there must be an easier way to do this?

This is interesting. I see what you are trying to do. Let me poke a Corvid master for you.

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
   });
}


So the above is your backend file, you need to import the sendMail function to your page so that you can call this backend function from the page. For that I suggest going through this article: Velo Web Modules: Calling Backend Code from the Frontend | Help Center | Wix.com

Thanks!

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!

@terrancehudson screenshot your backend file and page code. There must be a typo somewhere.

@shantanukumar847 The first time I forgot to include the getID function. Here’s the backend code:


and here’s the frontend code.


Now, its not displaying the textbox numbers, sending email to the current user or the backend user???

@terrancehudson You frontend and backend has bugs. For starters you cannot have 2 page onReady functions one inside the other.

2nd, you are importing the sendMail function from a backend file called ‘aModule’ which does not exist. The name of you backend file is ‘mail.jsw’

On your backend code, line 11 should be:

.eq('loginEmail', email)

I think you should read the documentation because it will give you an understanding of how the code works:

  • Wix Data Query

  • Calling Server Side code from page

  • Page’s onReady function

  • Sending Triggered Emails

@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 thank you so much for your detailed response! You’re a rockstar. :smiley:

Lets hook you up with a badge! You #CorvidMaster!

@shantanukumar847 Grrrr… frontend now looks like this:


and backend like this:


now filling status bar, textboxes and sending current user, but not to specific user?

@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!!!

@stevenjose I agree!!! After weeks of trying to get this to work because of @shan I can move forward! #CorvidMaster!

@terrancehudson YES! I am happy to hear this terrance!

Hey @brett did this get resolved or has anyone heard anything about this issue? I ask the same question here in the Corvid Forum group. Just want to see if I can develop this for my client. Here is the link: https://www.wix.com/corvid/forum/community-discussion/trigger-emails-doesn-t-work-for-a-non-current-user-how-can-i-make-it-work

Nino: Yes, I have it working just great! If you like, I can send the coding tomorrow (Monday).

@terrancehudson Please and thank you.

@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.

@terrancehudson Could you provided the code through a website tomorrow and I can take a look at the link?

@nino : The code is backend code. How about if I post just the code to send to non logged in member here?