Improve BccFromString to handle spaces and empty addresses

Trim spaces from email addresses and skip empty addresses in BccFromString method. This ensures that the BCC list only includes valid, non-empty email addresses, enhancing email sending reliability.
This commit is contained in:
Winni Neessen 2024-10-26 18:29:26 +02:00
parent 03cb09c3bd
commit f079ea09eb
Signed by: wneessen
GPG key ID: 385AC9889632126E

11
msg.go
View file

@ -942,7 +942,16 @@ func (m *Msg) BccIgnoreInvalid(rcpts ...string) {
// References:
// - https://datatracker.ietf.org/doc/html/rfc5322#section-3.6.3
func (m *Msg) BccFromString(rcpts string) error {
return m.Bcc(strings.Split(rcpts, ",")...)
src := strings.Split(rcpts, ",")
var dst []string
for _, address := range src {
address = strings.TrimSpace(address)
if address == "" {
continue
}
dst = append(dst, address)
}
return m.Bcc(dst...)
}
// ReplyTo sets the "Reply-To" address for the Msg, specifying where replies should be sent.