# Send email to NOT logged in member!

**URL:** <https://forum.wixstudio.com/t/send-email-to-not-logged-in-member/46894>\
**Category:** Ask the community\
**Tags:** wix-members-area, partners, code\
**Created:** [January 23, 2020, 4:31pm UTC](https://forum.wixstudio.com/t/send-email-to-not-logged-in-member/46894 "2020-01-23T16:31:29Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![terrancehudson](https://avatars.discourse-cdn.com/v4/letter/t/f475e1/32.png) [@terrancehudson](https://forum.wixstudio.com/u/terrancehudson)\
**Post date:** [January 23, 2020, 4:31pm UTC](https://forum.wixstudio.com/t/send-email-to-not-logged-in-member/46894/1 "2020-01-23T16:31:29Z")

</div>

#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](mailto: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?

---

<div class="post-metadata">

**Author:** ![eduardog](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/eduardog/32/669_2.png) [@eduardog](https://forum.wixstudio.com/u/eduardog)\
**Post date:** [January 24, 2020, 12:44am UTC](https://forum.wixstudio.com/t/send-email-to-not-logged-in-member/46894/2 "2020-01-24T00:44:34Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Shan](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/shan/32/106059_2.png) [@Shan](https://forum.wixstudio.com/u/Shan)\
**Post date:** [January 24, 2020, 1:00am UTC](https://forum.wixstudio.com/t/send-email-to-not-logged-in-member/46894/3 "2020-01-24T01:00:14Z")

</div>

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](https://www.wix.com/corvid/reference/wix-crm-backend.html) . 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.

```javascript
//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](https://support.wix.com/en/article/corvid-web-modules-calling-server-side-code-from-the-front-end)

---

<div class="post-metadata">

**Author:** ![terrancehudson](https://avatars.discourse-cdn.com/v4/letter/t/f475e1/32.png) [@terrancehudson](https://forum.wixstudio.com/u/terrancehudson)\
**Post date:** [January 24, 2020, 1:51am UTC](https://forum.wixstudio.com/t/send-email-to-not-logged-in-member/46894/4 "2020-01-24T01:51:54Z")

</div>

Thanks!

---

<div class="post-metadata">

**Author:** ![terrancehudson](https://avatars.discourse-cdn.com/v4/letter/t/f475e1/32.png) [@terrancehudson](https://forum.wixstudio.com/u/terrancehudson)\
**Post date:** [January 24, 2020, 1:59am UTC](https://forum.wixstudio.com/t/send-email-to-not-logged-in-member/46894/5 "2020-01-24T01:59:27Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![Shan](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/shan/32/106059_2.png) [@Shan](https://forum.wixstudio.com/u/Shan)\
**Post date:** [January 24, 2020, 3:44pm UTC](https://forum.wixstudio.com/t/send-email-to-not-logged-in-member/46894/6 "2020-01-24T15:44:10Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![terrancehudson](https://avatars.discourse-cdn.com/v4/letter/t/f475e1/32.png) [@terrancehudson](https://forum.wixstudio.com/u/terrancehudson)\
**Post date:** [January 24, 2020, 4:14pm UTC](https://forum.wixstudio.com/t/send-email-to-not-logged-in-member/46894/7 "2020-01-24T16:14:11Z")

</div>

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

![](https://static.wixstatic.com/media/a27d24_e56683ab86904ac39e7beac49398fc70~mv2.bmp)  
and here’s the frontend code.

![](https://static.wixstatic.com/media/a27d24_76253ab9b51a4fb8ac8e650a786eb8ee~mv2.bmp)  
Now, its not displaying the textbox numbers, sending email to the current user or the backend user???

---

<div class="post-metadata">

**Author:** ![Shan](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/shan/32/106059_2.png) [@Shan](https://forum.wixstudio.com/u/Shan)\
**Post date:** [January 24, 2020, 4:22pm UTC](https://forum.wixstudio.com/t/send-email-to-not-logged-in-member/46894/8 "2020-01-24T16:22:02Z")

</div>

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

```javascript
.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

---

<div class="post-metadata">

**Author:** ![terrancehudson](https://avatars.discourse-cdn.com/v4/letter/t/f475e1/32.png) [@terrancehudson](https://forum.wixstudio.com/u/terrancehudson)\
**Post date:** [January 24, 2020, 4:30pm UTC](https://forum.wixstudio.com/t/send-email-to-not-logged-in-member/46894/9 "2020-01-24T16:30:02Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![stevenjose](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/stevenjose/32/3202_2.png) [@stevenjose](https://forum.wixstudio.com/u/stevenjose)\
**Post date:** [January 24, 2020, 4:37pm UTC](https://forum.wixstudio.com/t/send-email-to-not-logged-in-member/46894/10 "2020-01-24T16:37:30Z")

</div>

@shantanukumar847 thank you so much for your detailed response! You’re a rockstar. 😃

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

---

<div class="post-metadata">

**Author:** ![terrancehudson](https://avatars.discourse-cdn.com/v4/letter/t/f475e1/32.png) [@terrancehudson](https://forum.wixstudio.com/u/terrancehudson)\
**Post date:** [January 24, 2020, 4:38pm UTC](https://forum.wixstudio.com/t/send-email-to-not-logged-in-member/46894/11 "2020-01-24T16:38:31Z")

</div>

@shantanukumar847 Grrrr… frontend now looks like this:

![](https://static.wixstatic.com/media/a27d24_75859528fdc94587be3c89f2992f1f0d~mv2.bmp)  
and backend like this:

![](https://static.wixstatic.com/media/a27d24_2454b0cc14b34e95bed6fb19e1a34a79~mv2.bmp)  
now filling status bar, textboxes and sending current user, but not to specific user?

---

<div class="post-metadata">

**Author:** ![terrancehudson](https://avatars.discourse-cdn.com/v4/letter/t/f475e1/32.png) [@terrancehudson](https://forum.wixstudio.com/u/terrancehudson)\
**Post date:** [January 24, 2020, 4:47pm UTC](https://forum.wixstudio.com/t/send-email-to-not-logged-in-member/46894/12 "2020-01-24T16:47:53Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![terrancehudson](https://avatars.discourse-cdn.com/v4/letter/t/f475e1/32.png) [@terrancehudson](https://forum.wixstudio.com/u/terrancehudson)\
**Post date:** [January 24, 2020, 4:50pm UTC](https://forum.wixstudio.com/t/send-email-to-not-logged-in-member/46894/13 "2020-01-24T16:50:47Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![stevenjose](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/stevenjose/32/3202_2.png) [@stevenjose](https://forum.wixstudio.com/u/stevenjose)\
**Post date:** [January 24, 2020, 5:04pm UTC](https://forum.wixstudio.com/t/send-email-to-not-logged-in-member/46894/14 "2020-01-24T17:04:57Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![nino](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/nino/32/2394_2.png) [@nino](https://forum.wixstudio.com/u/nino)\
**Post date:** [March 16, 2020, 1:55am UTC](https://forum.wixstudio.com/t/send-email-to-not-logged-in-member/46894/15 "2020-03-16T01:55:06Z")

</div>

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](https://www.wix.com/corvid/forum/community-discussion/trigger-emails-doesn-t-work-for-a-non-current-user-how-can-i-make-it-work)

---

<div class="post-metadata">

**Author:** ![terrancehudson](https://avatars.discourse-cdn.com/v4/letter/t/f475e1/32.png) [@terrancehudson](https://forum.wixstudio.com/u/terrancehudson)\
**Post date:** [March 16, 2020, 2:07am UTC](https://forum.wixstudio.com/t/send-email-to-not-logged-in-member/46894/16 "2020-03-16T02:07:43Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![nino](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/nino/32/2394_2.png) [@nino](https://forum.wixstudio.com/u/nino)\
**Post date:** [March 16, 2020, 2:09am UTC](https://forum.wixstudio.com/t/send-email-to-not-logged-in-member/46894/17 "2020-03-16T02:09:16Z")

</div>

@terrancehudson Please and thank you.

---

<div class="post-metadata">

**Author:** ![terrancehudson](https://avatars.discourse-cdn.com/v4/letter/t/f475e1/32.png) [@terrancehudson](https://forum.wixstudio.com/u/terrancehudson)\
**Post date:** [March 16, 2020, 2:15am UTC](https://forum.wixstudio.com/t/send-email-to-not-logged-in-member/46894/18 "2020-03-16T02:15:18Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![nino](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/nino/32/2394_2.png) [@nino](https://forum.wixstudio.com/u/nino)\
**Post date:** [March 16, 2020, 2:33am UTC](https://forum.wixstudio.com/t/send-email-to-not-logged-in-member/46894/19 "2020-03-16T02:33:15Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![terrancehudson](https://avatars.discourse-cdn.com/v4/letter/t/f475e1/32.png) [@terrancehudson](https://forum.wixstudio.com/u/terrancehudson)\
**Post date:** [March 16, 2020, 2:41am UTC](https://forum.wixstudio.com/t/send-email-to-not-logged-in-member/46894/20 "2020-03-16T02:41:07Z")

</div>

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

[Next page](https://forum.wixstudio.com/t/send-email-to-not-logged-in-member/46894.md?page=2)
