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:
Add the new import statement:
javascript | Copy Codeimport { triggeredEmails } from 'wix-crm-backend'If you plan to migrate all functions that use
wixCrmBackend
, remove the originalimport wixCrmBackend
statement.Look for any code that uses
wixCrmBackend.emailContact()
, and replace it withtriggeredEmails.emailContact()
. Update your code to work with the newemailContact()
call and response properties.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.
Syntax
function emailContact(emailId: string, toContact: string, [options: TriggeredEmailOptions]): Promise<void>
emailContact Parameters
NAME
TYPE
DESCRIPTION
The Email ID of the Triggered Email to send.
The contact's ID you are sending the email to.
Variable values to insert into the email.
Returns
Fulfilled - When the email is sent. Rejected - Error message.
Return Type:
Was this helpful?
Send a Triggered Email
This example uses a deprecated function.
1import wixCrmBackend from 'wix-crm-backend';23export function myBackendFunction() {4 let contactId = // get contact ID56 wixCrmBackend.emailContact("emailID", contactId)7 .then( () => {8 // email has been sent9 } )10 .catch( (err) => {11 // there was an error sending the email12 } );13}14