email.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. smtpSender := &SmtpSender{
  14. SmtpHost: servercfg.GetSmtpHost(),
  15. SmtpPort: servercfg.GetSmtpPort(),
  16. SenderEmail: servercfg.GetSenderEmail(),
  17. SendUser: servercfg.GetSenderUser(),
  18. SenderPass: servercfg.GetEmaiSenderPassword(),
  19. }
  20. if smtpSender.SendUser == "" {
  21. smtpSender.SendUser = smtpSender.SenderEmail
  22. }
  23. client = smtpSender
  24. }
  25. // EmailSender - an interface for sending emails based on notifications and mail templates
  26. type EmailSender interface {
  27. // SendEmail - sends an email based on a context, notification and mail template
  28. SendEmail(ctx context.Context, notification Notification, email Mail) error
  29. }
  30. type Mail interface {
  31. GetBody(info Notification) string
  32. GetSubject(info Notification) string
  33. }
  34. // Notification - struct for notification details
  35. type Notification struct {
  36. RecipientMail string
  37. RecipientName string
  38. ProductName string
  39. }
  40. func GetClient() (e EmailSender) {
  41. return client
  42. }