Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implements feature #1578 - CC and BCC on custom headers #1865

Merged
merged 1 commit into from
May 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions internal/messenger/email/email.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"math/rand"
"net/smtp"
"net/textproto"
"strings"

"github.com/knadh/listmonk/models"
"github.com/knadh/smtppool"
Expand All @@ -14,6 +15,8 @@ import (
const (
emName = "email"
hdrReturnPath = "Return-Path"
hdrBcc = "Bcc"
hdrCc = "Cc"
)

// Server represents an SMTP server's credentials.
Expand Down Expand Up @@ -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)
Expand Down
Loading