netmaker/email/email.go
2024-07-25 11:17:19 +05:30

53 lines
1.1 KiB
Go

package email
import (
"context"
"github.com/gravitl/netmaker/servercfg"
)
type EmailSenderType string
var client EmailSender
const (
Smtp EmailSenderType = "smtp"
Resend EmailSenderType = "resend"
)
func init() {
switch EmailSenderType(servercfg.EmailSenderType()) {
case Smtp:
client = &SmtpSender{
SmtpHost: servercfg.GetSmtpHost(),
SmtpPort: servercfg.GetSmtpPort(),
SenderEmail: servercfg.GetSenderEmail(),
SenderPass: servercfg.GetEmaiSenderAuth(),
}
case Resend:
client = NewResendEmailSenderFromConfig()
}
client = GetClient()
}
// EmailSender - an interface for sending emails based on notifications and mail templates
type EmailSender interface {
// SendEmail - sends an email based on a context, notification and mail template
SendEmail(ctx context.Context, notification Notification, email Mail) error
}
type Mail interface {
GetBody(info Notification) string
GetSubject(info Notification) string
}
// Notification - struct for notification details
type Notification struct {
RecipientMail string
RecipientName string
ProductName string
}
func GetClient() (e EmailSender) {
return client
}