Skip to main content

Method 3) Custom method

This method allows you provide a callback using which you can send emails however you like. The input to the callback will be email template variables, so you can freely design the email as well. Use this method if you are:

  • Using a third party email service like Mailchimp.
  • You want to do some custom spam protection before sending the email.
  • You already have an email sending infrastructure and want to use that.
import supertokens from "supertokens-node";
import Passwordless from "supertokens-node/recipe/passwordless";
import Session from "supertokens-node/recipe/session";

supertokens.init({
appInfo: {
apiDomain: "...",
appName: "...",
websiteDomain: "..."
},
recipeList: [
Passwordless.init({
emailDelivery: {
override: (originalImplementation) => {
return {
...originalImplementation,
sendEmail: async function ({
codeLifetime, // amount of time the code is alive for (in MS)
email,
urlWithLinkCode, // magic link
userInputCode, // OTP
}) {
// TODO: create and send email
}
}
}
},
}),
Session.init()
]
});

If you call the original implementation function for sendEmail, it will use the service that you have configured. If you have not configured any service, it will use the default service.

important

When using this callback, you must manage sending the email yourself.

Looking for older versions of the documentation?
Which UI do you use?
Custom UI
Pre built UI