SendEmail never read Email.BccAddress, so the player recipients attached as Bcc were silently dropped from the SMTP envelope and only the hardcoded To address (the sender) ever received the mail. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
35 lines
833 B
Go
35 lines
833 B
Go
package email
|
|
|
|
import (
|
|
"net/smtp"
|
|
"strconv"
|
|
"strings"
|
|
)
|
|
|
|
func SendEmail(email *Email) error {
|
|
config, err := NewConfigFromEnv()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return sendEmail(config.Username, config.Password, config.SmtpServer, int(SMTP_SERVICE), email.ToAddress, email.BccAddress, email.Subject, email.Body)
|
|
}
|
|
|
|
func sendEmail(username, password, server string, port int, to []string, bcc []string, subject, body string) error {
|
|
auth := smtp.PlainAuth("", username, password, server)
|
|
|
|
msg := "From: " + username + "\r\n" +
|
|
"To: " + strings.Join(to, ",") + "\r\n" +
|
|
"Subject: " + subject + "\r\n" +
|
|
"\r\n" +
|
|
body
|
|
|
|
recipients := append(append([]string{}, to...), bcc...)
|
|
|
|
err := smtp.SendMail(server+":"+strconv.Itoa(port), auth, username, recipients, []byte(msg))
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|