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

Add support for additional headers #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
14 changes: 14 additions & 0 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ type config struct {
Subject string
From *mail.Address
HeaderFrom *mail.Address
Headers Headers
To *mail.Address
ShowErr bool
StartTLS bool
Expand All @@ -58,6 +59,17 @@ type config struct {
Client *smtp.Client
}

type Headers []string

func (h *Headers) String() string {
return strings.Join(*h, ",")
}

func (h *Headers) Set(value string) error {
*h = append(*h, value)
return nil
}

func (cfg *config) trackErr(stage string, err error, limiter chan struct{}) {
atomic.AddUint64(fps, 1)
if limiter == nil {
Expand Down Expand Up @@ -383,6 +395,7 @@ func main() {
flag.BoolVar(&cfg.ShowErr, "show-error", false, "show error type on auth failure")
flag.BoolVar(&cfg.StartTLS, "starttls", true, "whether to require StartTLS")
flag.BoolVar(&cfg.ReuseSMTP, "reuse-smtp", false, "Reuse SMTP connection")
flag.Var(&cfg.Headers, "header", "Additional headers")
flag.Parse()

// SMTP credentials
Expand Down Expand Up @@ -428,6 +441,7 @@ func main() {
cfg.Msg = "To: " + cfg.To.Address + "\r\n" +
"From: " + cfg.HeaderFrom.String() + "\r\n" +
"Subject: " + cfg.Subject + "\r\n" +
strings.Join(cfg.Headers, "\r\n") + "\r\n" +
"\r\n" +
randStringBytes(cfg.Size) +
"\r\n"
Expand Down