Send Reminder failures were silently swallowed, only surfacing in the HTTP response and never in the application log, unlike the GM notification email flows. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
40 lines
1 KiB
Go
40 lines
1 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"log"
|
|
"net/http"
|
|
"strings"
|
|
|
|
"github.com/hculpan/areweplaying/cmd/web/templates"
|
|
"github.com/hculpan/areweplaying/pkg/email"
|
|
)
|
|
|
|
func sendEmailHandler(w http.ResponseWriter, r *http.Request) {
|
|
if !ValidateJWTFromCookie(r, appKey) {
|
|
http.Error(w, "Unauthorized", http.StatusUnauthorized)
|
|
return
|
|
}
|
|
|
|
r.ParseForm()
|
|
bcc := r.FormValue("to")
|
|
from := "culpanvtt@gmail.com"
|
|
subject := r.FormValue("subject")
|
|
body := r.FormValue("text")
|
|
bccArray := strings.Split(bcc, ",")
|
|
for i := range bccArray {
|
|
bccArray[i] = strings.Trim(bccArray[i], " \t\n\r")
|
|
}
|
|
e := email.NewEmail([]string{from}, bccArray, from, subject, body)
|
|
|
|
// log.Default().Printf("got email: To: %s, From: %s, Subject: %q, Body: %q", to, from, subject, body)
|
|
err := email.SendEmail(e)
|
|
if err != nil {
|
|
log.Default().Printf("ERROR sending email: %s", err)
|
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
return
|
|
}
|
|
|
|
comp := templates.SendEmail("Email sent!", "")
|
|
comp.Render(context.Background(), w)
|
|
}
|