+3
-8
appview/email/email.go
+3
-8
appview/email/email.go
···
1
1
package email
2
2
3
3
import (
4
-
"fmt"
5
4
"net"
6
5
"regexp"
7
6
"strings"
···
11
10
12
11
type Email struct {
13
12
From string
14
-
To string
15
13
Subject string
16
14
Text string
17
15
Html string
18
16
APIKey string
19
17
}
20
18
21
-
func SendEmail(email Email) error {
19
+
func SendEmail(email Email, recipients ...string) error {
22
20
client := resend.NewClient(email.APIKey)
23
21
_, err := client.Emails.Send(&resend.SendEmailRequest{
24
22
From: email.From,
25
-
To: []string{email.To},
23
+
To: recipients,
26
24
Subject: email.Subject,
27
25
Text: email.Text,
28
26
Html: email.Html,
29
27
})
30
-
if err != nil {
31
-
return fmt.Errorf("error sending email: %w", err)
32
-
}
33
-
return nil
28
+
return err
34
29
}
35
30
36
31
func IsValidEmail(email string) bool {
+2
-3
appview/settings/settings.go
+2
-3
appview/settings/settings.go
···
117
117
return email.Email{
118
118
APIKey: s.Config.Resend.ApiKey,
119
119
From: s.Config.Resend.SentFrom,
120
-
To: emailAddr,
121
120
Subject: "Verify your Tangled email",
122
121
Text: `Click the link below (or copy and paste it into your browser) to verify your email address.
123
122
` + verifyURL,
···
130
129
func (s *Settings) sendVerificationEmail(w http.ResponseWriter, did, emailAddr, code string, errorContext string) error {
131
130
emailToSend := s.buildVerificationEmail(emailAddr, did, code)
132
131
133
-
err := email.SendEmail(emailToSend)
132
+
err := email.SendEmail(emailToSend, emailAddr)
134
133
if err != nil {
135
-
log.Printf("sending email: %s", err)
134
+
log.Printf("failed to send email: %s", err)
136
135
s.Pages.Notice(w, "settings-emails-error", fmt.Sprintf("Unable to send verification email at this moment, try again later. %s", errorContext))
137
136
return err
138
137
}
+1
-2
appview/signup/signup.go
+1
-2
appview/signup/signup.go
···
149
149
em := email.Email{
150
150
APIKey: s.config.Resend.ApiKey,
151
151
From: s.config.Resend.SentFrom,
152
-
To: emailId,
153
152
Subject: "Verify your Tangled account",
154
153
Text: `Copy and paste this code below to verify your account on Tangled.
155
154
` + code,
···
157
156
<p><code>` + code + `</code></p>`,
158
157
}
159
158
160
-
err = email.SendEmail(em)
159
+
err = email.SendEmail(em, emailId)
161
160
if err != nil {
162
161
s.l.Error("failed to send email", "error", err)
163
162
s.pages.Notice(w, noticeId, "Failed to send email.")