Triggered Emails

We are excited to announce that you can now send stunning, personalized emails to users who are logged-in to your site using the Wix Code API. You begin by designing an email template that can contain variables. From your code, you choose which template to send and what content to inject into the template.

How it works

  1. Design at least one email template using Triggered Emails .

  2. In code:

  3. Choose which email template you want to use.

  4. Retrieve the information you want to use in place of the template’s variables.

  5. Call the emailUser() function from your page code.

Example

In this example, we send an email to a user when a form has been submitted successfully. To read more about the code in this example, see How to Send a Triggered Email with Code .

import wixUsers from 'wix-users';

$w.onReady(function () {  
  $w("#sportDataset").onAfterSave( () => {
    if(wixUsers.currentUser.loggedIn) {    
    const userId = wixUsers.currentUser.id;
 
    wixUsers.emailUser("sportMail", userId, {
      variables: {
        "name": $w("#nameInput").value,
        "sport": $w("#sportDropdown").value,
        "comments": $w("#commentsInput").value
      }
    })
      .then( () => {
         // do something after the email was sent successfully
      })
      .catch( (err) => {
         // handle error that prevented the email from being sent
      });
    }
  });
});

Learn more

To learn more, see emailUser in the API reference.

10 Likes

Hi Yoav - this may see foo topic but it’s major problems to whoever has lot’s of sites - all your tools to contact users are good one site per tome - i’ve numerous sites and i don’t have one screen i can have over site when i get traffic in - need one screen like Wix Expert screen that simply each site will show notification - otherwise i need to open 20 CRM - it’s an edge the APP has over desktop version

Small note regarding TriggeredEmails - TriggeredEmails are still not open to all users - we are in the process of making it available for all. We just could not wait with the good news…

1 Like

Sakis has just posted this video on the FB group about emailUser -

Great video!

2 Likes

Hey Yoav, can you please add me, it seem like a thing I asked about and I know I will love it.

Ok I missed that you can only trigger mail to logged in users, then we don’t have ny use of it. We use our own registration process when doing applications and we need this but we need to send it to emailaddresses and not registred users only. Hope that you will open up for that soon, it will blast my work and then I can add money to you instead of SendGrid.

2 Likes

Here’s mine …

2 Likes

As Andreas Kviby said, this does not work for my application requiring the user to be signed in. I would like to use triggered emails to users submitting a form without having to use a third party like SendGrid.

Are there plans to add this functionality?

2 Likes

A great step but sending to only registered users is disapointing and handcuffs more intersting use cases. I hope an email can simply be triggered and sent to anyone sooner rather than later.

Thanks, Wix Team!

2 Likes

Are you not able to add dynamic links to TriggeredEmails? I don’t see any option to do so when adding a link or button to the e-mail templates.

4 Likes

Bump last post. I think the answer is no, but it seems so obvious that we should be able to do it.

Hi Yoav me too, I have need to link a dynamic page on button email. It’s in order to create a way to confirm a new member on my site. Is ti possible ? Thanks in advance

1 Like

Andreas / Peter / Karson: This is just the first phase of Triggered Emails, I am sure they will surprise us soon enough.

David / Mauro: Yes, you can the line that says “.then” is where you would enter the URL you want. If you don’t know how to type in a dynamic URL, then read the members article .

Essentially you would have something like this:

wixLocation.to(`/Members/${wixUsers.currentUser.id}`); 

Hopefully sooner rather than later, but I definitely appreciate all the great changes and additions they are making.

Expanding triggered emails and opening up stores/checkout page so I can tie shipping to an external api call would solve all of my problems…right now :slight_smile:

1 Like

Nayeli – Can you confirm, are we talking about the same thing? I think you’re saying I can re-direct to a certain page after the e-mail is sent. I get that.

I am talking about literally within the e-mail, I need to add a button that when they click it opens up a dynamic URL page.

1 Like

Oh … IN the email. No …because the email they receive will be in no way connected to your database. (No matter if you use this or any other email). What you could do is have them land on a “fake page” and then do an auto redirect to the dynamic url. I have a code for auto redirect on my Totally Codable forum.

1 Like

Right, I know for a fact it can be done in normal SenGrid and I imagine triggeredEmails is just a Wix front end for that, so this must just be a feature they haven’t implemented yet.

In theory, in the same way we replace text like ${replacement_text} using Wix variables, we should be able to do using a button. What a bummer.

3 Likes

David, perfect !

I believe, missing this simple feature, that the exit way could be to send in the confirmation email a random code that the new member have to insert in a confirmation page on the site

Correct. But remember those variables are being “filled in” from the page code. So if we had those variables on the email … were do you theoretically suppose they would be retrieved the information from?