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 ThirdPartyEmailPassword from "supertokens-node/recipe/thirdpartyemailpassword";
import Session from "supertokens-node/recipe/session";
import EmailVerification from "supertokens-node/recipe/emailverification"

supertokens.init({
appInfo: {
apiDomain: "...",
appName: "...",
websiteDomain: "..."
},
recipeList: [
ThirdPartyEmailPassword.init({
emailDelivery: {
override: (originalImplementation) => {
return {
...originalImplementation,
sendEmail: async function (input) {
// TODO: create and send password reset email

// Or use the original implementation which calls the default service,
// or a service that you may have specified in the emailDelivery object.
return originalImplementation.sendEmail(input);
}
}
}
},
}),

// if email verification is enabled
EmailVerification.init({
emailDelivery: {
override: (originalImplementation) => {
return {
...originalImplementation,
sendEmail: async function (input) {
// TODO: create and send email verification email

// Or use the original implementation which calls the default service,
// or a service that you may have specified in the emailDelivery object.
return originalImplementation.sendEmail(input);
}
}
}
},
}),
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.

So using this method, you can for example, have your custom way of sending email verification emails, but use the default or SMTP service to send the reset password emails.

important

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

Which UI do you use?
Custom UI
Pre built UI