top of page

Send Wix Triggered Emails with Velo: Backend Code Example

Writer: Faysal Jaali
Faysal Jaali
Sep 8, 2023
5 min read

Updated: Nov 2

Use Wix’s backend triggeredEmails.emailContact method to send a published triggered-email template to a Wix contact. The template ID and contact ID are different values, and personalization variables must match the template.


This article provides an administrator-only test method. For template preparation and the overall submission workflow, start with setting up triggered emails.


how to send triggered emails using wix velo

Prepare a small controlled test


Publish a template containing a firstName variable and copy its email ID. Choose a test contact you are authorized to email and confirm its subscription status.


The official emailContact reference documents the current triggeredEmails namespace, recipient rules and options. The earlier wix-crm-backend.emailContact function is deprecated; an import named sendTriggeredEmail from wix-users-backend is not the API used in this example.


Add an admin-only web method


Create backend/triggered-email.web.js and replace the template placeholder with your published template ID.


// backend/triggered-email.web.js
import { webMethod, Permissions } from "@wix/web-methods";
import { triggeredEmails } from "wix-crm-backend";

const templateId = "REPLACE_WITH_YOUR_PUBLISHED_TEMPLATE_ID";

export const sendTestEmail = webMethod(
  Permissions.Admin,
  async (contactId, firstName) => {
    if (typeof contactId !== "string" || !contactId.trim()) {
      throw new Error("A Wix contact ID is required.");
    }
    if (typeof firstName !== "string" || firstName.length > 80) {
      throw new Error("Check the first name.");
    }
    try {
      await triggeredEmails.emailContact(templateId, contactId.trim(), {
        variables: { firstName: firstName.trim() }
      });
      return { accepted: true };
    } catch {
      throw new Error("The test email request failed. Check the template and contact.");
    }
  }
);

The webMethod documentation explains Permissions.Admin. This test endpoint is available to site administrators rather than every visitor.


The template is fixed in backend code. The method checks the contact ID and bounds the first-name input before making the request.


Call the test method


From an admin-only test page, import sendTestEmail from backend/triggered-email.web. Call it with the selected Wix contact ID and a test first name.


The accepted result means the awaited operation completed without throwing. It should not be displayed as proof that a person received or read the message.


Do not paste a real customer’s contact details into a public example. Use a test identity and remove diagnostic information before sharing screenshots.


Understand contacts, members and variables


A contact ID is not interchangeable with a member ID. Choose the corresponding API when your workflow is specifically member-based and follow that method’s documentation.


The firstName key in the example must exist in the selected template. If your template uses a different variable name, change both deliberately. Avoid passing an entire form object as template variables.


Wix’s documentation says contacts marked unsubscribed do not receive an email through this method. Respect the contact’s actual state rather than attempting to bypass it.


screenshot showing how to add dynamic value to triggered email in Wix
Original illustration of inserting a dynamic variable into a triggered email.

Adapt the pattern to a real submission


A production acknowledgement should be sent after a valid business event, with the recipient resolved on the backend. Add duplicate handling tied to a durable submission record.


Do not simply change Permissions.Admin to Permissions.Anyone and allow the caller to choose any contact. A public form needs its own validation, abuse controls and identity-handling design.


Test the failure paths


Confirm that ordinary visitors cannot invoke the admin-only endpoint. Test a missing contact ID, a name over the limit, incorrect template configuration and a rejected provider request.


Confirm the template content in the destination inbox. Then check a repeat invocation so the team understands that an explicit second send request can create another email.


Match the code to a published template


In this example, replace templateId with the identifier of the intended published triggered-email template. Add a variable named firstName in that template if you want the supplied value to appear. The restored screenshots illustrate the template area and variable insertion workflow; they are not a substitute for checking the identifier used by your site.


Choose an existing Wix contact you are authorized to use for a test. A contact ID is not the same value as an email address or a member ID. The method calls emailContact, so confirm that you are supplying the contact identifier expected by that operation.


Create backend/triggered-email.web.js and preserve the administrator permission while testing. Import sendTestEmail from backend/triggered-email.web in the controlled test workflow. Pass the contact ID and a permitted first-name string in that order.


screenshot of triggered email page on WIX
Original Wix Triggered Emails dashboard illustration.

Interpret the result correctly


The method returns accepted: true after the sending operation completes successfully. That result describes the request path; it is not a receipt proving delivery, inbox placement or reading. Check the actual recipient’s test inbox and the relevant Wix diagnostics when evaluating delivery.


The sample trims the contact identifier and first name and limits the first-name length. It does not look up a business transaction or establish that a particular customer is entitled to a message. A production event needs that server-side connection to the relevant saved record.


Handle variable and contact problems separately


If the email is accepted but the greeting is wrong, check the template variable name and the supplied value. If the operation fails, check the template identifier, its publication state, the contact identifier and the rules applying to that contact and message. Changing the subject line will not repair a wrong recipient identifier.


Use a minimal template for the first test. Once the variable appears correctly and the delivery path has been checked, add the final content and links. This staged approach makes it easier to identify which change introduced a problem.


Adapt the example around the business event


For an enquiry acknowledgement, save and validate the enquiry first, derive the recipient through the trusted backend workflow and then request the relevant email. Prevent duplicate notifications for the same event. Keep an appropriate record of the request state so a temporary sending failure can be investigated.


Do not convert the test into a public “send to any contact” function. Restrict the operation to the intended event and the data it is allowed to use. The triggered-email setup guide covers the template, event and handoff decisions that surround this small code example.


Test the inputs and outcomes


Test case

Expected behavior

What it establishes

Valid contact and first name

Request accepted when provider and template permit it

The send operation completed without a reported error

Empty contact identifier

Validation error

Missing recipient identifiers are rejected

First name longer than 80 characters

Validation error

The example input boundary is enforced

Wrong template identifier

Controlled sending error

The failure path is usable

API accepted; no inbox message

Investigate reporting and recipient state

Acceptance and delivery are different observations


Use authorized test contacts and inspect actual received messages before relying on this path. For page-level validation and confirmation checks, use the landing-page checklist.


What was tested for this example?


Local tests checked permission selection, input validation, template-variable mapping and error propagation with a simulated Wix email API. No customer email was sent as part of the article review.


Can I use this for a bulk marketing campaign?


This example is a single triggered-email workflow. A campaign requires a separately appropriate tool, recipient permissions and sending process.


For help connecting accepted form submissions to your team’s process, contact CodeMasters.

bottom of page