From f079ea09eb4b1856ca1dd93d3ab1d5544dd7ee22 Mon Sep 17 00:00:00 2001 From: Winni Neessen Date: Sat, 26 Oct 2024 18:29:26 +0200 Subject: [PATCH] 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. --- msg.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/msg.go b/msg.go index 587894f..c96bfac 100644 --- a/msg.go +++ b/msg.go @@ -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.