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
- Other Frameworks
Important
For other backend frameworks, you can follow our guide on how to spin up a separate server configured with the SuperTokens backend SDK to authenticate requests and issue session tokens.
import supertokens from "supertokens-node";
import Passwordless from "supertokens-node/recipe/passwordless";
import Session from "supertokens-node/recipe/session";
import { SMTPService } from "supertokens-node/recipe/passwordless/emaildelivery";
supertokens.init({
appInfo: {
apiDomain: "...",
appName: "...",
websiteDomain: "..."
},
recipeList: [
Passwordless.init({
emailDelivery: {
service: new SMTPService({
smtpSettings: {
host: "...",
authUsername: "...", // this is optional. In case not given, from.email will be used
password: "...",
port: 465,
from: {
name: "...",
email: "...",
},
secure: true
},
})
},
}),
Session.init()
]
});
import (
"github.com/supertokens/supertokens-golang/ingredients/emaildelivery"
"github.com/supertokens/supertokens-golang/recipe/passwordless"
"github.com/supertokens/supertokens-golang/recipe/passwordless/plessmodels"
"github.com/supertokens/supertokens-golang/supertokens"
"crypto/tls"
)
func main() {
smtpUsername := "..."
supertokens.Init(supertokens.TypeInput{
RecipeList: []supertokens.Recipe{
passwordless.Init(plessmodels.TypeInput{
EmailDelivery: &emaildelivery.TypeInput{
Service: passwordless.MakeSMTPService(emaildelivery.SMTPServiceConfig{
Settings: emaildelivery.SMTPSettings{
Host: "...",
From: emaildelivery.SMTPFrom{
Name: "...",
Email: "...",
},
Port: 465,
Username: &smtpUsername, // this is optional. In case not given, from.email will be used
Password: "...",
Secure: false,
// this is optional. TLS config is used if Secure is set to true, or server supports STARTTLS
// if not provided, the SDK will use a default config
TLSConfig: &tls.Config{
// ...
},
},
}),
},
}),
},
})
}
from supertokens_python import init, InputAppInfo
from supertokens_python.recipe import passwordless
from supertokens_python.ingredients.emaildelivery.types import EmailDeliveryConfig, SMTPSettings, SMTPSettingsFrom
init(
app_info=InputAppInfo(
api_domain="...", app_name="...", website_domain="..."),
framework='...',
recipe_list=[
passwordless.init(
email_delivery=EmailDeliveryConfig(
service=passwordless.SMTPService(
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
)
)
)
)
]
)
To learn about how to customise the default email templates or the subject, please see the next section.