Velo → Triggered Emails → Emails Not Sending

I’m using triggeredEmails.emailClient.sendEmail() in a .jsw backend file. My site is on a Premium plan and published. I’ve confirmed that my template ID (UlEvmRi ) is correct and variables are matching. But every time I call the function, it returns “Unable to handle the request” — even though the code is correct and previously worked in preview/testing. Please confirm that my triggered email feature is active and my template ID is properly linked on Wix’s backend.

Hi, @Chris_Kelly !!

Your code might still work even with some fixes, but since .jsw files are now deprecated :melting_face:, this could be a good opportunity to rewrite it using the new .web.js format. Also, there’s a newer version of triggeredEmails available, so you might want to consider switching to that as well. I’ve included the relevant references for you below. :innocent:

Lastly, here’s a simple explanation of how to do it. That said, the steps are almost the same as when using .jsw files, so there’s no need to worry. First, add a “Web Module” to your backend, and create a file like sample.web.js. Then, write code like the example below (taken from the reference) inside that file.

import { Permissions, webMethod } from "wix-web-module";
import { triggeredEmails } from "wix-crm-backend";

export const myEmailContactFunction = webMethod(
  Permissions.Anyone,
  (emailId, contactId) => {
    return triggeredEmails
      .emailContact(emailId, contactId)
      .then(() => {
        console.log("Email was sent to contact");
      })
      .catch((error) => {
        console.error(error);
      });
  },
);

After that, just import and use the .web.js file on the frontend the same way you used to with .jsw. :grin:

I don’t think it’s a good idea to hardcode values like emailId or contactId directly in the frontend code, so you may need to implement your own security measures to handle that appropriately.

2 Likes