-
Notifications
You must be signed in to change notification settings - Fork 41
Open
Description
Hi
my use case is to send an email to all registered users, my solution looks like this:
create SMTP Service
// override email delivery to set custom content
func notificationEmailOverrides(originalImplementation emaildelivery.SMTPInterface) emaildelivery.SMTPInterface {
(*originalImplementation.GetContent) = func(input emaildelivery.EmailType, userContext supertokens.UserContext) (emaildelivery.EmailContent, error) {
user := input.EmailVerification.User
content := emaildelivery.EmailContent{
Body: notificationEmailBody,
IsHtml: true,
Subject: notificationEmailSubject,
ToEmail: user.Email,
}
return content, nil
}
return originalImplementation
}
// SMTP Service to send emails
var Email *emaildelivery.EmailDeliveryInterface
func foo() {
// ...
// create SMTP service instance
Email = emailverification.MakeSMTPService(emaildelivery.SMTPServiceConfig{
Settings: smtpSettings,
Override: notificationEmailOverrides,
})
// ...
sendNotificationEmail(...)
// ...
}
func sendNotificationEmail(userId string, email string, tenantId string, userContext supertokens.UserContext) {
// we abuse the email type EmailVerification here, because we need to set any type and there is no custom type yet
input := emaildelivery.EmailType{EmailVerification: &emaildelivery.EmailVerificationType{
User: emaildelivery.User{
ID: userId,
Email: email,
},
EmailVerifyLink: "",
TenantId: tenantId,
}}
err := (*Email.SendEmail)(input, userContext)
return err
}As you can see in sendNotificationEmail i set EmailType to EmailVerification because it is not possible to specify a custom type.
Is there any better solution or is it possible to update EmailType like this:
type EmailType struct {
EmailVerification *EmailVerificationType
PasswordReset *PasswordResetType
PasswordlessLogin *PasswordlessLoginType
Custom *CustomType
}
type CustomType struct {
User User
Data map[string]interface{}{} // or use pointer type
TenantId string
}Thanks
Metadata
Metadata
Assignees
Labels
No labels