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

Handle CC and BCC as recipients #21

Closed
wants to merge 1 commit into from
Closed
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
7 changes: 7 additions & 0 deletions cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"net/smtp"
"os"
"os/user"
"strings"
)

import flag "github.com/spf13/pflag"
Expand Down Expand Up @@ -72,6 +73,12 @@ func Go() {
// We only need to parse the message to get a recipient if none where
// provided on the command line.
recip = append(recip, msg.Header.Get("To"))
for _,cc := range strings.Split(msg.Header.Get("Cc"), ",") {
recip = append(recip, strings.TrimSpace(cc))
}
for _,bcc := range strings.Split(msg.Header.Get("Bcc"), ",") {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure if this works correctly. As far as I know the Bcc is no part of the header, right?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Worked for me, I was using my fork for a while.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This probably won't work correctly if there's a comma as part of the recipient's name (in quotes).

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didnt think of that use case, good catch. Unfortunately I no longer use msendmail, if someone else wants to pick up this PR please feel free. I don't think it will get merged however. I've been using swaks with maildev instead.

recip = append(recip, strings.TrimSpace(bcc))
}
}

err = smtp.SendMail(smtpAddr, nil, fromAddr, recip, body)
Expand Down