Search.../

emailContact( )

Deprecated. This function will continue to work, but a newer version is available at wix-crm-backend.triggeredEmails.emailContact().

Description

Sends a Triggered Email to a contact.

Migration Instructions

If this function is already in your code, it will continue to work. To stay compatible with future changes, migrate to wix-crm-backend.triggeredEmails.emailContact().

To migrate to the new function:

  1. Add the new import statement:

    import { triggeredEmails } from 'wix-crm-backend'
    javascript | Copy Code
  2. If you plan to migrate all functions that use wixCrmBackend, remove the original import wixCrmBackend statement.

  3. Look for any code that uses wixCrmBackend.emailContact(), and replace it with triggeredEmails.emailContact(). Update your code to work with the new emailContact() call and response properties.

  4. Test your changes to make sure your code behaves as expected.

To learn more about Triggered Emails, see:

Before using the emailContact() 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 contact the email is sent to by passing a contact's ID in the toContact parameter.

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

Authorization

Request

This endpoint does not take any parameters

Response Object

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

Returns an empty object.

Status/Error Codes

Was this helpful?

Send a Triggered Email

This example uses a deprecated function.

Copy Code
1import { Permissions, webMethod } from 'wix-web-module';
2import wixCrmBackend from 'wix-crm-backend';
3
4export const myBackendFunction = webMethod(Permissions.Anyone, () => {
5 let contactId = // get contact ID
6
7 wixCrmBackend.emailContact("emailID", contactId)
8 .then( () => {
9 // email has been sent
10 } )
11 .catch( (err) => {
12 // there was an error sending the email
13 } );
14});