| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- 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
- }
|