Search.../

emailMember( )

Sends a Triggered Email to the currently logged-in site member.

Description

To learn more about Triggered Emails, see:

Before using the emailMember() function, you need to set up at least one Triggered Email.

Specify which email to send by passing the email's ID in the emailId parameter.

Specify which member the email is sent to by passing the member's user ID in the toUser parameter. 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 currentMember.

If the specified Triggered Email contains variables, you can pass values for those variables using the optional options parameter. You pass a TriggeredEmailOptions object which contains the values to be inserted into your email in place of the variables defined in that email. The values passed must be strings. If the object you pass to the options parameter does not contain a key:value pair for a variable in your Triggered Email, the fallback value defined when creating your Triggered Email is inserted in place of the variable.

Note that Triggered Emails generates a code snippet for each of your email templates. The generated code includes the email's ID and keys for all the email's variable names. You can copy and paste the snippet into your code. Then, you need to define values for the toUser property and for each variable key. To learn how to use the generated snippet in your code, see How to Send a Triggered Email with Code.

Note: The APIs in wix-crm-frontend are only partially functional when previewing your site. View a published version of your site to see their complete functionality.

Syntax

function emailMember(emailId: string, memberId: string, [options: TriggeredEmailOptions]): Promise<void>

emailMember Parameters

NAME
TYPE
DESCRIPTION
emailId
string

ID of the triggered email to send.

memberId
string

ID of the currently signed-in member to send the email to.

options
Optional
TriggeredEmailOptions

Variable values to insert into the email.

Returns

Fulfilled - When the email is sent. Rejected - Error message.

Return Type:

Promise<void>

Was this helpful?

Send a triggered email to the current member

Copy Code
1import { triggeredEmails } from 'wix-crm-frontend';
2
3// ...
4
5// Sample emailId value:
6// 'thanks_for_joining'
7//
8// Sample memberId value:
9// '72751428-2743-4bda-acf5-4218a4279cd3'
10
11triggeredEmails.emailMember(emailId, memberId)
12 .then(() => {
13 console.log('Email was sent to member');
14 })
15 .catch((error) => {
16 console.error(error);
17 });
Send a triggered email to the current member with variables

Copy Code
1import { triggeredEmails } from 'wix-crm-frontend';
2
3// ...
4
5// Sample emailId value:
6// 'thanks_for_joining'
7//
8// Sample memberId value:
9// '72751428-2743-4bda-acf5-4218a4279cd3'
10//
11// Sample options value:
12// {
13// variables: {
14// firstName: 'Johnny',
15// lastName: 'Appleseed'
16// }
17// }
18
19triggeredEmails.emailMember(emailId, memberId, options)
20 .then(() => {
21 console.log('Email was sent to member');
22 })
23 .catch((error) => {
24 console.error(error);
25 });