diff --git a/appview/email/email.go b/appview/email/email.go index 052b160f..fe0b4eeb 100644 --- a/appview/email/email.go +++ b/appview/email/email.go @@ -1,7 +1,6 @@ package email import ( - "fmt" "net" "net/mail" "strings" @@ -11,26 +10,22 @@ import ( type Email struct { From string - To string Subject string Text string Html string APIKey string } -func SendEmail(email Email) error { +func SendEmail(email Email, recipients ...string) error { client := resend.NewClient(email.APIKey) _, err := client.Emails.Send(&resend.SendEmailRequest{ From: email.From, - To: []string{email.To}, + To: recipients, Subject: email.Subject, Text: email.Text, Html: email.Html, }) - if err != nil { - return fmt.Errorf("error sending email: %w", err) - } - return nil + return err } // AddNewsletterContact creates a global contact in Resend and adds them to the newsletter segment. diff --git a/appview/settings/settings.go b/appview/settings/settings.go index 2f955fc0..3517d278 100644 --- a/appview/settings/settings.go +++ b/appview/settings/settings.go @@ -354,7 +354,6 @@ func (s *Settings) buildVerificationEmail(emailAddr, did, code string) email.Ema return email.Email{ APIKey: s.Config.Resend.ApiKey, From: s.Config.Resend.SentFrom, - To: emailAddr, Subject: "Verify your Tangled email", Text: `Click the link below (or copy and paste it into your browser) to verify your email address. ` + verifyURL, @@ -367,9 +366,9 @@ func (s *Settings) buildVerificationEmail(emailAddr, did, code string) email.Ema func (s *Settings) sendVerificationEmail(w http.ResponseWriter, did, emailAddr, code string, errorContext string) error { emailToSend := s.buildVerificationEmail(emailAddr, did, code) - err := email.SendEmail(emailToSend) + err := email.SendEmail(emailToSend, emailAddr) if err != nil { - s.Logger.Error("sending email", "err", err) + s.Logger.Error("failed to send email", "err", err) s.Pages.Notice(w, "settings-emails-error", fmt.Sprintf("Unable to send verification email at this moment, try again later. %s", errorContext)) return err } diff --git a/appview/signup/signup.go b/appview/signup/signup.go index ee51d402..03e854a9 100644 --- a/appview/signup/signup.go +++ b/appview/signup/signup.go @@ -165,7 +165,6 @@ func (s *Signup) signup(w http.ResponseWriter, r *http.Request) { em := email.Email{ APIKey: s.config.Resend.ApiKey, From: s.config.Resend.SentFrom, - To: emailId, Subject: "Verify your Tangled account", Text: `Copy and paste this code below to verify your account on Tangled. ` + code, @@ -173,7 +172,7 @@ func (s *Signup) signup(w http.ResponseWriter, r *http.Request) {

` + code + `

`, } - err = email.SendEmail(em) + err = email.SendEmail(em, emailId) if err != nil { s.l.Error("failed to send email", "error", err) s.pages.Notice(w, noticeId, "Failed to send email.")