mirror of
https://github.com/gravitl/netmaker.git
synced 2025-10-04 02:44:29 +08:00
53 lines
1.1 KiB
Go
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
|
|
}
|