Published onĀ 

Sending a welcome email to new users with Plunk and Auth0

Auth0, is one of the leading authentication providers in the world. Making it easy to securely handle user signups and logins. With third-party Oauth providers, you can easily offer your users their preferred authentication method without too much hassle.

When a users first signs up is a great time to send them an email with a welcome message. A welcome email is one of the best ways to create a good first impression for your users. In this article you will learn how you can use Auth0 actions with Plunk to send a welcome email to new users when they sign up through Auth0.

Sending emails to your users with Auth0 and Plunk

How does Plunk work?

As you may already know, Plunk operates with events that you can trigger through a single API endpoint. Making it a super flexible tool since you can trigger them from literally anywhere! These events can be anything, you name it! Signup, project deleted, subscription cancelled and many more. Allowing you to trigger complex email workflows from practically anywhere.

You can already create a new project on the Plunk dashboard to get started.

1. Triggering an event

Luckily for us, Auth0 makes it really easy to trigger events when someone signs up. Before we get started, make sure you have your Plunk private key ready.

Head over to your Plunk dashboard's API settings and copy your private key.

On your Auth0 dashboard, head to the Actions tab. Actions are automated flows that are triggered on certain events. We are going to be creating a new flow that will send an event to Plunk when someone signs up.

Create a new flow with the Post User Registration template and add the following code to it.

2 * @param {Event} event - Details about registration event.
3 */
4exports.onExecutePostUserRegistration = async (event) => {
5  const Plunk = require('@plunk/node');
6  const plunk = new Plunk.default(event.secrets.PLUNK_API_KEY);
8  await{
9    email:,
10    event: 'account-created'
11  });

Head to the secrets tab of your new flow and add a secret called PLUNK_API_KEY, the value of this secret is the secret key you copied from your Plunk dashboard.

To complete the setup, go to the dependencies tab and add @plunk/node as a dependency. You can pick a fixed version or just enter latest.

If you did all the setup correctly, you should see that there are no longer any errors present in the code editor.

An image showing Auth0's code editor without any errors
An image showing Auth0's code editor without any errors

Save your action and hit deploy. Every time a user signs up through Auth0, Plunk will receive the account-created event.

Now that our account-created events are being sent to Plunk, we can use them to create automated workflows that trigger every time someone creates an account. Allowing us to send them a friendly welcome email!

You can also find the code sample in the Plunk examples repository

2. Creating our template

Let's head over to our Plunk dashboard and create a new email template. There are many ways to do this but the built-in drag-and-drop editor is by far the easiest!

An image showing Plunk's built-in drag-and-drop email editor
An image showing Plunk's built-in drag-and-drop email editor

Save your template once you have that perfect design and let's link it all together with an action!

3. Creating an action

Actions are your automated workflows. They take in events and automatically send emails to users that have completed the required ones.

You can create up to two automated workflows on the free plan. Find the create button on the actions tab. Give your action a name, select your account-created event and the template you just saved.

We suggest you also toggle the Run once toggle, just to make sure users only receive a single email when they sign up!

Testing it out

Once you have saved your action, your Plunk setup is up and running. Users will now receive emails when they create an account in your application through Auth0. Easy right?

Go ahead and test it out with your own email! If you already used it to trigger the event, don't worry you can always delete your user in the dashboard!

Plunk's welcome email to new users
Plunk's welcome email to new users

Personalizing it

A great marketing email should always be personalized. Luckily, you can easily do this with Plunk! All we need to do is associate data to our users that we can then use in our templates. Let's say that you also collect their name during the signup process with the custom fields array and you want to store that information in Plunk.

Changing our event publish function

2    email: "",
3    event: "account-created",
4    data: {
5      name: "Plunk",
6    }
7  });

Updating our template

By also adding the data parameter to our Plunk event, we can store extra data about our users and use it in our emails. Let's update the template you created in the previous steps.

Variables are automatically inserted in emails if they exist in the user. All you need to do is let Plunk know where it should place them. For this you make use of the {{variable}} syntax. Where you replace the word variable with the name of the variable you want to insert. In our case that would look something like this {{name}}

Variables are supported in both the subject and the body of the email, making it really easy to personalize the emails you are sending out! Because let's be honest, who doesn't want to see their name in an email?

Some common questions

What other tools does Plunk work with?

Plunk works with all tools and languages that can send API calls. We also have some integrations with some third-party no-code tools like Zapier.

What else can I use Plunk for?

You can use Plunk in many scenarios to send marketing emails to your users. One example we really like is sending an email when something happens in your Stripe account.

Do I really need email marketing?

We know, marketing is a pain. Don't underestimate it's power though! Especially email marketing is still very effective in 2022. Several statistics show us that content marketing through email, like newsletters, is still the most effective way to reach your users.