Platform
Docs
Solutions
ContactLog In

Get started sending notifications with Courier in minutes, not days!

We have SDKs in Ruby, Go, Python, Javascript, Node.js, and React.

Sign up

seo-blog
TUTORIAL

Stop (Only) Sending Password Reset Emails

Shreya Gupta

July 03, 2023

You’ve got to stop sending password reset emails. Everyone does it and it’s not cool anymore. Many of your users don’t want to log into their email or open the mail app just to get access to a code that they have to manually copy and paste into your app — it’s a waste of time. Most phones support autofilling codes sent via SMS, which might make SMS the preferred channel for these users. However, you also can’t assume that this is how everyone will behave. You need to let your user decide how they receive their notifications, which means giving them the option between SMS, email, or whatever other channel they prefer.

Generalizing user behavior can lead to unnecessary reduction in user engagement on your app, which will eventually lead to decreased user retention. Preferences matter, and they’re easy to set up. Let’s walk through two ways in which you can implement an amazing password reset notification experience for your users, by communicating with them via their preferred channels.

Skip the Steps

Here’s how you might be sending password reset emails today using the Courier SDK:

  1. Install the Courier SDK by running the following command:
1
pip install trycourier
  1. Add the following code and replace <API_KEY> with your Courier API key:
1
from trycourier import Courier
2
3
client = Courier(auth_token="<API_KEY>")
4
5
resp = client.send_message(
6
message={
7
"to": {
8
"email": "example@email.com",
9
},
10
"content": {
11
"title": "Hi!",
12
"body": "You have requested to log in. Your access code is {{code}}. Use this link to reset your password: {{link}}.",
13
},
14
"data": {
15
"link": "<insert_link_here>",
16
"code": "283hf2"
17
}
18
}
19
)
20
21
print(resp['requestId'])

For best practices, make sure to use environment variables to store your API keys!

By adding your user’s phone_number and setting the routing.method to all, you can send via email and SMS. When this API call is made, your user will receive both an email and an SMS, and they can access the message from the most convenient option.

1
from trycourier import Courier
2
3
client = Courier(auth_token="<API_KEY>")
4
5
resp = client.send_message(
6
message={
7
"to": {
8
"email": "example@email.com",
9
"phone_number": "123-456-7890"
10
},
11
"content": {
12
"title": "Hi!",
13
"body": "You have requested to log in. Your access code is {{code}}. Use this link to reset your password: {{link}}.",
14
},
15
"data": {
16
"link": "<insert_link_here>",
17
"code": "283hf2"
18
},
19
"routing": {
20
"method": "single",
21
"channels": ["email", "sms"],
22
},
23
}
24
)
25
26
print(resp['requestId'])

To send password reset notifications via all channels, just replace the "single" with "all" in the routing object.

Let’s Build

Part 1: Set up a Preferences Center

With a Preferences Center, you can enable your users to share specifically how they want to receive their notifications. Courier is a notifications infrastructure that provides a customizable out-of-the-box Preferences Center.

  1. In Courier go to the Preferences Designer.
  2. Click on the + Topic button.
  3. Change the Subscription Topic Name to Account Management.
  4. Change the Default state of Account Management to required so that users cannot opt out of receiving notifications attached to this Topic
  5. Hit Save to save changes.

Part 2: Create a Notification

Notifications designed in Courier can be tagged with Subscription Topics that allow you to categorize them. Learn more >.

stop-pword-reset-emails1

  1. Go to the Notification Designer.
  2. Click Create Template to create a new Notification Template.
  3. In the pop-up menu, add Password Reset in the title and attach the Account Management Subscription Topic to this Template.
  4. Click Create Template and add all the channels you can send the Password Reset message through (email, SMS, and any others your users can receive this message at).

stop-pword-reset-emails2

  1. Customize your message for each channel.
  2. Add a link to the Preference Center {$.urls.preferences}

stop-pword-reset-emails3

  1. Publish your notification template.

Part 3: Send

The following code will make an API call to Courier to send the Notification Template we just created.

  1. Add the following code to your application.
  2. Copy your template ID from your Notification Template settings and paste it as the value for the template property.
  3. Make sure to add all of the user’s profile information in the to object (learn more about what profile info you will need for each channel).
1
from trycourier import Courier
2
3
client = Courier(auth_token="<API_KEY>")
4
5
resp = client.send_message(
6
message={
7
"to": {
8
"email": "example@email.com",
9
"phone_number": "123-456-7890"
10
},
11
"template": "0ZP3AH34H945QHPNZ2S0NF7X1RNB",
12
"data": {
13
"link": "<insert_link_here>",
14
"code": "283hf2"
15
},
16
"routing": {
17
"method": "single",
18
"channels": ["email", "sms"],
19
},
20
}
21
)
22
23
print(resp['requestId'])

This API call is very similar to the code in the first method we used to send. However, since the Notification Template is attached to a Subscription Topic, your app will now automatically respect your user’s preferences instead of sending messages on all channels.

stop-pword-reset-emails4

Conclusion

Let’s rethink our approach to password reset notifications. The traditional method of sending password reset notifications via emails is no longer convenient or efficient for many users. By assuming that everyone will follow the same behavior pattern, you risk alienating a significant portion of your user base.

To provide an exceptional user experience, you must empower your users to choose how they receive their notifications. Whether it's through SMS, email, or any other preferred channel, offering this flexibility demonstrates that you value their time and preferences.

Get started sending notifications with Courier in minutes, not days!

We have SDKs in Ruby, Go, Python, Javascript, Node.js, and React.

Sign up

More from Tutorial

How to set up automatic push notifications based on Segment events thumbnail
TUTORIAL

How to Set Up Automatic Push Notifications Based on Segment Events

Push notifications have carved their own niche as a powerful tool for continuous user engagement. Regardless of whether an app is actively in use, they deliver your messages straight to your user's device. Two key players that can combine to enhance your push notification strategy are Segment and Courier. In this tutorial, we show you how to set up Courier to listen to your Segment events and then send push notifications to an Android device based on data from these events.

Sarah Barber

Sarah Barber

November 17, 2023

image14
TUTORIAL

How to Send Firebase Notifications to iOS Devices Using Courier

This tutorial explains how to send push notifications to iOS devices from your iOS application code using Firebase FCM and Courier’s iOS SDK.

Martina Caccamo

Martina Caccamo

November 01, 2023

Build your first notification in minutes

Send up to 10,000 notifications every month, for free.

Get started for free

Email & push notification

Build your first notification in minutes

Send up to 10,000 notifications every month, for free.

Get started for free

Email & push notification

Platform

Users

Content

Channels

Sending

Workflows

Preferences

Inbox

Workspaces

Observability

API Status

Changelog

© 2024 Courier. All rights reserved.