Provide SMTP configuration
Using this method, you can:
- Send emails using your own domain
- Optionally customise the default email templates and subject.
- NodeJS
- GoLang
- Python
import supertokens from "supertokens-node";
import EmailPassword from "supertokens-node/recipe/emailpassword";
import Session from "supertokens-node/recipe/session";
import { SMTPService } from "supertokens-node/recipe/emailpassword/emaildelivery";
import EmailVerification from "supertokens-node/recipe/emailverification"
import { SMTPService as EmailVerificationSMTPService } from "supertokens-node/recipe/emailverification/emaildelivery";
let smtpSettings = {
host: "...",
authUsername: "...", // this is optional. In case not given, from.email will be used
password: "...",
port: 465,
from: {
name: "...",
email: "...",
},
secure: true
}
supertokens.init({
appInfo: {
apiDomain: "...",
appName: "...",
websiteDomain: "..."
},
recipeList: [
EmailPassword.init({
emailDelivery: {
service: new SMTPService({smtpSettings})
},
}),
// if email verification is enabled..
EmailVerification.init({
emailDelivery: {
service: new EmailVerificationSMTPService({smtpSettings})
}
}),
Session.init()
]
});
import (
"github.com/supertokens/supertokens-golang/ingredients/emaildelivery"
"github.com/supertokens/supertokens-golang/recipe/emailpassword"
"github.com/supertokens/supertokens-golang/recipe/emailpassword/epmodels"
"github.com/supertokens/supertokens-golang/recipe/emailverification"
"github.com/supertokens/supertokens-golang/recipe/emailverification/evmodels"
"github.com/supertokens/supertokens-golang/supertokens"
)
func main() {
smtpUsername := "..."
smtpSettings := emaildelivery.SMTPSettings{
Host: "...",
From: emaildelivery.SMTPFrom{
Name: "...",
Email: "...",
},
Port: 456,
Username: &smtpUsername, // this is optional. In case not given, from.email will be used
Password: "...",
Secure: false,
}
supertokens.Init(supertokens.TypeInput{
RecipeList: []supertokens.Recipe{
emailpassword.Init(&epmodels.TypeInput{
EmailDelivery: &emaildelivery.TypeInput{
Service: emailpassword.MakeSMTPService(emaildelivery.SMTPServiceConfig{
Settings: smtpSettings,
}),
},
}),
// if email verification is enabled
emailverification.Init(evmodels.TypeInput{
EmailDelivery: &emaildelivery.TypeInput{
Service: emailverification.MakeSMTPService(emaildelivery.SMTPServiceConfig{
Settings: smtpSettings,
}),
},
}),
},
})
}
from supertokens_python import init, InputAppInfo
from supertokens_python.recipe import emailpassword
from supertokens_python.ingredients.emaildelivery.types import EmailDeliveryConfig, SMTPSettingsFrom, SMTPSettings
from supertokens_python.recipe import emailverification
smtp_settings = SMTPSettings(
host="...",
port=465,
from_=SMTPSettingsFrom(
name="...",
email="..."
),
password="...",
secure=False,
username="..." # this is optional. In case not given, from_.email will be used
)
init(
app_info=InputAppInfo(
api_domain="...", app_name="...", website_domain="..."),
framework='...',
recipe_list=[
emailpassword.init(
email_delivery=EmailDeliveryConfig(
service=emailpassword.SMTPService(
smtp_settings=smtp_settings
)
)
),
# If email verification is enabled
emailverification.init(
mode="OPTIONAL",
email_delivery=EmailDeliveryConfig(
service=emailverification.SMTPService(
smtp_settings=smtp_settings
)
)
)
]
)
To learn about how to customise the default email templates or the subject, please see the next section.