File length: 8469 # Platform Configuration - Email delivery Source: https://supertokens.com/docs/platform-configuration/email-delivery ## Overview SuperTokens sends emails in different authentication scenarios. The method applies in the `EmailPassword`, `Passwordless`, and `AccountLinking` recipes. The following page shows you how to configure the email delivery method and adjust the content that gets sent to your users. ## Delivery methods ### Default service If you provide no configuration for email delivery, the backend SDK sends emails by talking to the servers on `https://api.supertokens.com` This applies to both self hosted and managed services. :::important - No info sent to the API that sends out emails on behalf of your app is logged or stored. - The system sends emails using `noreply@supertokens.io` email ID. If you want to use your own domain, please see one of the other methods in this section. - You cannot customize the email template when using this method. If you want to customize the emails, please see one of the other methods in this section. - Emails sent via the service are free and may land up in user's spam due to the high number of apps that use the service. If you want to avoid this, we recommend using one of the other methods mentioned in this section. ::: --- ### SMTP service Using this method, you can provide your own SMTP server's configuration and the system sends the emails using those. Use this method if you want to: - Send emails using your own domain. - Optionally customize the default email template and subject. ```tsx // highlight-start let smtpSettings = { host: "...", authUsername: "...", // this is optional. In case not given, from.email will be used password: "...", port: 465, from: { name: "...", email: "...", }, secure: true } // highlight-end supertokens.init({ appInfo: { apiDomain: "...", appName: "...", websiteDomain: "..." }, recipeList: [ EmailPassword.init({ // highlight-start emailDelivery: { service: new SMTPService({smtpSettings}) }, // highlight-end }), // if email verification is enabled.. EmailVerification.init({ mode: "OPTIONAL", // highlight-start emailDelivery: { service: new EmailVerificationSMTPService({smtpSettings}) } // highlight-end }), Session.init() ] }); ``` ```go supertokens.init({ appInfo: { apiDomain: "...", appName: "...", websiteDomain: "..." }, recipeList: [ EmailPassword.init({ // highlight-start 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); } } } }, // highlight-end }), // if email verification is enabled EmailVerification.init({ mode: "OPTIONAL", // highlight-start 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); } } } }, // highlight-end }), Session.init() ] }); ``` ```go ```tsx supertokens.init({ appInfo: { apiDomain: "...", appName: "...", websiteDomain: "..." }, recipeList: [ EmailPassword.init({ emailDelivery: { service: new SMTPService({ // @ts-ignore smtpSettings: { /*...*/ }, // highlight-start override: (originalImplementation) => { return { ...originalImplementation, getContent: async function (input) { // password reset content let { passwordResetLink, 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; } } } // highlight-end }) } }), // if email verification is enabled EmailVerification.init({ mode: "OPTIONAL", emailDelivery: { service: new EmailVerificationSMTPService({ // @ts-ignore smtpSettings: { /*...*/ }, // highlight-start 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; } } } // highlight-end }) } }), Session.init() ] }); ``` ```go supertokens.init({ appInfo: { apiDomain: "...", appName: "...", websiteDomain: "..." }, recipeList: [ EmailPassword.init({ // highlight-start emailDelivery: { override: (originalImplementation) => { return { ...originalImplementation, sendEmail: async function (input) { // TODO: run some logic before sending the email await originalImplementation.sendEmail(input); // TODO: run some logic post sending the email } } } }, // highlight-end }), // if email verification is enabled EmailVerification.init({ mode: "OPTIONAL", // highlight-start emailDelivery: { override: (originalImplementation) => { return { ...originalImplementation, sendEmail: async function (input) { // TODO: run some logic before sending the email await originalImplementation.sendEmail(input); // TODO: run some logic post sending the email } } } }, // highlight-end }), Session.init() ] }); ``` ```go