# How to set up Email OTP solution in Flow Builder

In this guide, you’ll learn how to set up a one-time password (OTP) email solution with [Flow Builder](https://dashboard.messagebird.com/en/flow-builder). OTPs are single-use passcodes that allow you to verify your customers' identity.

&#x20;

### **Requirements**

* [A MessageBird account](https://dashboard.messagebird.com/en/sign-up)
* The Email OTP Send flow and Email OTP Verification flow [JSON files](https://app.box.com/s/66dxx41teqwhpoyfeo0713hkirz3oxxf)
* [Postman](https://www.postman.com/downloads/) (to test your Email OTP solution)

### **Before you begin**

* Familiarize yourself with [Flow Builder](https://dashboard.messagebird.com/en/flow-builder), which can be reached from your MessageBird Dashboard.
* If you’d like to send authentication emails from your email domain (we'll show you how to do this in Step 2), you’ll need to [install Email as a channel](https://dashboard.messagebird.com/en/channels/email/new). For detailed instructions, go to our [guide](https://docs.bird.com/connectivity-platform/installing-channels/install-your-custom-email-domain-as-an-inbox-channel).

**Pro tip:** In this guide, we’ll use screenshots to help you navigate through the more technical set up steps.&#x20;

&#x20;

### **Step 1: Set up and connect the Email OTP Send and Email OTP Verification flows in Flow Builder**

\
Once set up, the Email OTP Send flow will send an OTP to your customer. The Email OTP Verification flow will check the input that your customer returns against the original OTP. If it matches, the customer will be sent a **Success** email. If it doesn't match, the customer will be sent a **Failed** email.

&#x20;

1\. Log in to your [MessageBird Dashboard](https://dashboard.messagebird.com/en/login) and go to [Flow Builder](https://dashboard.messagebird.com/en/flow-builder).

2\. Click **Import Flow**, upload and import the Email OTP Send JSON file, which you can download [here](https://app.box.com/s/66dxx41teqwhpoyfeo0713hkirz3oxxf). You’ll be taken to the flow.&#x20;

3\. **Publish** the Email OTP Send flow. You don’t need to copy the webhook URL from the dialogue box.

4\. Navigate back to [Flow Builder](https://dashboard.messagebird.com/en/flow-builder).

5\. Click **Import Flow**, upload and import the Email OTP Verification JSON file, which you can download [here](https://app.box.com/s/66dxx41teqwhpoyfeo0713hkirz3oxxf). You’ll be taken to the flow.&#x20;

6\. **Publish** the Email OTP Verification flow.

7\. Copy the **webhook URL** from the dialogue box that appears. You’ll also be able to find and copy this webhook URL in the **Webhook** step, as demonstrated in the screenshot below.<br>

<br>

<figure><img src="https://675349995-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUJNEE9TMK4fU91VKstBr%2Fuploads%2Fgit-blob-fa0dea1fefa1b5a31dbd5c6981868e539c53acc7%2FEmail_OTP_Verification_Webhook_step.png?alt=media" alt=""><figcaption></figcaption></figure>

\ <br>

8\. With the webhook URL copied, navigate back to the Email OTP Send flow. Go to the **HTTP Request** step and paste the URL into the URL field, as shown in the screenshot below.

&#x20;

<figure><img src="https://675349995-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUJNEE9TMK4fU91VKstBr%2Fuploads%2Fgit-blob-9765ee72519ae95b3d5461ad44651c1db323ac2c%2FEmail_OTP_Send_flow_HTTP_request.png?alt=media" alt=""><figcaption></figcaption></figure>

\ <br>

9\. Go to the very end of the URL that you’ve just pasted into the URL field and add the following query string:

```
?otp={{random[0]}}
```

Your URL should now look similar to this: <https://flows.messagebird.com/flows/5540bbfb-71db-42ca-b421-88eadbf0cc26/invoke?otp=\\{{random\\[0]\\}}>

10\. **Save** the changes you’ve made to the **HTTP Request** step.

11\. **Publish** the Email OTP Send flow.

&#x20;

### **Step 2: Create a custom email channel (optional)**

\
By default, the flows you’ve just set up will use MessageBird’s **flows.messagebird.com** email domain to send OTP emails. If you would prefer to send OTP emails from your email domain, you can create a custom email channel by updating the Email OTP Send flow and the Email OTP Verification flow as follows:\ <br>

#### Update the Email OTP Send flow

Use this screenshot as a reference as you follow the steps.

&#x20;

<figure><img src="https://675349995-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUJNEE9TMK4fU91VKstBr%2Fuploads%2Fgit-blob-57cd04bd6ddacbc67d7f834f15f9afede239766c%2FEmail_OTP_Send_flow_overview.png?alt=media" alt=""><figcaption></figcaption></figure>

&#x20;

1\. [Install your own email domain as an Email Inbox channel](https://docs.bird.com/connectivity-platform/installing-channels/install-your-custom-email-domain-as-an-inbox-channel).

2\. From Flow Builder, navigate to the Email OTP Send flow.

3\. Add the **Send conversation message** step to your flow, placing it below the **HTTP Request** step and above the **Send an email** step. You can do this by dragging and dropping the new step from the **Steps** menu, or by clicking the plus symbol between the two existing steps.

4\. In the settings of the new **Send conversation message** step, select **Inbox Email** from the Channel drop-down menu.&#x20;

5\. Drag and drop the **email** variable from the Available variables list into the Recipient field.

6\. In the Originator name field, type in an identifying name, such as **OTP**.&#x20;

7\. In the Address field, enter the name of the email address you want to send OTP emails from. There’s no need to include the domain name here, as this information will be added automatically when an OTP email is sent.

8\. In the Subject field, type in the subject line for your OTP emails. If you want to include the verification code in the subject line itself, you can drag and drop the **random(0)** variable from the Available variables list, as shown in the screenshot.

9\. In the Content field, type in the email body text for your OTP emails, using a little basic HTML to format the email content. Remember to include the **random(0)** variable in your message, as seen in the screenshot, as this will display your customer’s verification code.&#x20;

10\. **Save** the changes you’ve made to the **Send conversation message** step.

11\. **Delete** the **Send an email** step from your flow.&#x20;

12\. Publish your Email OTP Send flow.\ <br>

#### Update the Email OTP Verification flow<br>

Use this screenshot as a reference as you follow the steps.<br>

&#x20;

<figure><img src="https://675349995-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUJNEE9TMK4fU91VKstBr%2Fuploads%2Fgit-blob-d8c91f765d4ea9778cf5947b2702dcc04aaf042e%2FEmail_OTP_Verification_flow_overview.png?alt=media" alt=""><figcaption></figcaption></figure>

\ <br>

1\. Navigate to the Email OTP Verification flow

2\. Add the **Send conversation message** step to your flow, placing it below the **otp equals** condition of the **If/Else** branch and before the **Send an email** step. See **A1** in the screenshot for more details.&#x20;

3\. In the settings of the new **Send conversation message** step, select **Inbox Email** from the Channel drop-down menu.

4\. Drag and drop the **email** variable from the Available variables list into the Recipient field. You can do this by dragging and dropping the new step from the **Steps** menu, or by clicking the plus symbol between the two existing steps.

5\. In the settings of the new **Send conversation message** step, select **Inbox Email** from the Channel drop-down menu.

6\. Drag and drop the **email** variable from the Available variables list into the Recipient field.

7\. In the Originator name field, type in an identifying name, such as **OTP**.&#x20;

8\. In the Address field, enter the name of the email address you want to send OTP **Success** emails from. There’s no need to include the domain name here, as this information will be added automatically when an OTP email is sent.

9\. In the Subject field, type in a subject line for your OTP **Success** emails (e.g., **Your account has been verified**).&#x20;

10\. In the Content field, type in the email body text for your OTP **Success** email, using a little basic HTML to format the email content.&#x20;

11\. **Save** the changes you’ve made to the Send conversation message step.

12\. **Delete** the Send an email step below the Send conversation message step that you’ve just set up.

13\. Add a second **Send conversation message** step to your flow, placing it below the **Else** condition of the **If/Else** branch and before the Send an email step. See **A2** in the screenshot for more details.

14\. Repeat steps 3 through 7.

15\. In the Address field, enter the name of the email address you want to send OTP **Failed** emails from. There’s no need to include the domain name here, as this information will be added automatically when an OTP email is sent.

16\. In the Subject field, type in a subject line for your OTP **Failed** emails (e.g., **Your account has not been verified**).&#x20;

17\. In the Content field, type in the email body text for your OTP **Failed** email, using a little basic HTML to format the email content.&#x20;

18\. **Save** the changes you’ve made to the **Send conversation message** step.

19\. **Delete** the Send an email step below the Send conversation message step that you’ve just set up.

20\. **Publish** your email OTP Verification flow.

### &#x20;**Step 3: Test your Email OTP solution**

\
To test your Email OTP solution, install[ Postman](https://www.postman.com/downloads/). Set up two HTTP requests as shown in the screenshots below.

&#x20;

<figure><img src="https://675349995-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUJNEE9TMK4fU91VKstBr%2Fuploads%2Fgit-blob-dcf80d10eded283e1c9dd90c367f05e7ea123949%2FPostman_HTTP_request_1.png?alt=media" alt=""><figcaption></figcaption></figure>

\ <br>

<figure><img src="https://675349995-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUJNEE9TMK4fU91VKstBr%2Fuploads%2Fgit-blob-8e755cda7febe2309af55b235633259d83cf85bc%2FPostman_2.png?alt=media" alt=""><figcaption></figcaption></figure>

&#x20;

### **Step 4: Implement your OTP Email solution**

&#x20;

1\. To trigger the OTP, implement the **Webhook URL** of the Webhook step in the Email OTP send flow.

2\. To verify the OTP, implement the **Webhook URL** of the Await webhook step in the Email Verification flow.&#x20;

&#x20;

Please take note: the **identifier** variable is the user’s email address.

&#x20;

And that’s it! 🎉  Now you know how to set up an Email OTP solution through [Flow Builder](https://dashboard.messagebird.com/en/flow-builder).&#x20;

&#x20;
