email.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. package email
  2. import (
  3. "context"
  4. "github.com/gravitl/netmaker/servercfg"
  5. )
  6. type EmailSenderType string
  7. var client EmailSender
  8. const (
  9. Smtp EmailSenderType = "smtp"
  10. Resend EmailSenderType = "resend"
  11. )
  12. func init() {
  13. switch EmailSenderType(servercfg.EmailSenderType()) {
  14. case Smtp:
  15. client = &SmtpSender{
  16. SmtpHost: servercfg.GetSmtpHost(),
  17. SmtpPort: servercfg.GetSmtpPort(),
  18. SenderEmail: servercfg.GetSenderEmail(),
  19. SenderPass: servercfg.GetEmaiSenderAuth(),
  20. }
  21. case Resend:
  22. client = NewResendEmailSenderFromConfig()
  23. }
  24. client = GetClient()
  25. }
  26. // EmailSender - an interface for sending emails based on notifications and mail templates
  27. type EmailSender interface {
  28. // SendEmail - sends an email based on a context, notification and mail template
  29. SendEmail(ctx context.Context, notification Notification, email Mail) error
  30. }
  31. type Mail interface {
  32. GetBody(info Notification) string
  33. GetSubject(info Notification) string
  34. }
  35. // Notification - struct for notification details
  36. type Notification struct {
  37. RecipientMail string
  38. RecipientName string
  39. ProductName string
  40. }
  41. func GetClient() (e EmailSender) {
  42. return client
  43. }