Skip to content

High performance, self-hosted, newsletter and mailing list manager with a modern dashboard. Single binary app.

parse cc and bcc from custom headers to add them on email envelope (#1865)

Sergey Minkov3babd9020e01
diff --git a/internal/messenger/email/email.go b/internal/messenger/email/email.go
index ecb56b40..ed688431 100644
--- a/internal/messenger/email/email.go
+++ b/internal/messenger/email/email.go
@@ -6,6 +6,7 @@ import (
"math/rand"
"net/smtp"
"net/textproto"
+ "strings"
"github.com/knadh/listmonk/models"
"github.com/knadh/smtppool"
@@ -14,6 +15,8 @@ import (
const (
emName = "email"
hdrReturnPath = "Return-Path"
+ hdrBcc = "Bcc"
+ hdrCc = "Cc"
)
// Server represents an SMTP server's credentials.
@@ -146,6 +149,22 @@ func (e *Emailer) Push(m models.Message) error {
em.Headers.Del(hdrReturnPath)
}
+ // If the `Bcc` header is set, it should be set on the Envelope
+ if bcc := em.Headers.Get(hdrBcc); bcc != "" {
+ for _, part := range strings.Split(bcc, ",") {
+ em.Bcc = append(em.Bcc, strings.TrimSpace(part))
+ }
+ em.Headers.Del(hdrBcc)
+ }
+
+ // If the `Cc` header is set, it should be set on the Envelope
+ if cc := em.Headers.Get(hdrCc); cc != "" {
+ for _, part := range strings.Split(cc, ",") {
+ em.Cc = append(em.Cc, strings.TrimSpace(part))
+ }
+ em.Headers.Del(hdrCc)
+ }
+
switch m.ContentType {
case "plain":
em.Text = []byte(m.Body)