Skip to main content

Change email content

To change the content of the default email templates, you can override the getContent function in the emailDelivery object. It allows you to return an object that has the following properties:

  • body: This is the email's body. This can be HTML or just text as well.
  • isHtml: If the body is HTML, then this should be true.
  • subject: This is the subject of the email to send.
  • toEmail: The email will be sent to this email.

Other information like which email ID to send from is specified in the smtpSettings object.

import supertokens from "supertokens-node";import ThirdPartyPasswordless from "supertokens-node/recipe/thirdpartypasswordless";import Session from "supertokens-node/recipe/session";import { SMTPService } from "supertokens-node/recipe/thirdpartypasswordless/emaildelivery";import EmailVerification from "supertokens-node/recipe/emailverification"import { SMTPService as EmailVerificationSMTPService } from "supertokens-node/recipe/emailverification/emaildelivery";
supertokens.init({    appInfo: {        apiDomain: "...",        appName: "...",        websiteDomain: "..."    },    recipeList: [        ThirdPartyPasswordless.init({            emailDelivery: {                service: new SMTPService({                    smtpSettings: { /*...*/ },                    override: (originalImplementation) => {                        return {                            ...originalImplementation,                            getContent: async function (input) {                                                               let {                                    codeLifetime, // amount of time the code is alive for (in MS)                                    email,                                    urlWithLinkCode, // magic link                                    userInputCode, // OTP                                } = input;
                                // send some custom email content                                return {                                    body: "EMAIL BODY",                                    isHtml: true,                                    subject: "Some subject",                                    toEmail: email                                }                            }                        }                    }                })            }        }),
        // if email verification is enabled        EmailVerification.init({            emailDelivery: {                service: new EmailVerificationSMTPService({                    smtpSettings: { /*...*/ },                    override: (originalImplementation) => {                        return {                            ...originalImplementation,                            getContent: async function (input) {                                // email verification content                                let { emailVerifyLink, user } = input;
                                // you can even call the original implementation and modify that                                let originalContent = await originalImplementation.getContent(input)                                originalContent.subject = "My custom subject";                                return originalContent;                            }                        }                    }                })            }        }),
        Session.init()    ]});
Which frontend SDK do you use?
supertokens-web-js / mobile
supertokens-auth-react