Skip to content

Commit

Permalink
feat(output): add bcc to mail plugin
Browse files Browse the repository at this point in the history
close #89
  • Loading branch information
ncarlier committed Jul 8, 2024
1 parent 1db5529 commit 45749a2
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions pkg/output/plugins/email_plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@ var emailSpec = model.Spec{
Desc: "To (comma-separated list of email addresses)",
Type: model.Text,
},
{
Name: "bcc",
Desc: "Bcc (comma-separated list of email addresses)",
Type: model.Text,
},
{
Name: "subject",
Desc: "Subject format (by default: \"[feedpushr] {{.Title}}\"",
Expand Down Expand Up @@ -121,8 +126,9 @@ func (p *EmailOutputPlugin) Build(def *model.OutputDef) (model.Output, error) {
return nil, fmt.Errorf("missing From property")
}
to := def.Props.Get("to")
if to == "" {
return nil, fmt.Errorf("missing To property")
bcc := def.Props.Get("bcc")
if to == "" && bcc == "" {
return nil, fmt.Errorf("missing To or Bcc property")
}
formatValue := defaultEmailBodyFormat
if formatProp, ok := def.Props["format"]; ok && formatProp != "" {
Expand Down Expand Up @@ -153,6 +159,7 @@ func (p *EmailOutputPlugin) Build(def *model.OutputDef) (model.Output, error) {
conn: conn,
from: from,
to: to,
bcc: bcc,
}, nil
}

Expand All @@ -167,6 +174,7 @@ type EmailOutputProvider struct {
conn string
from string
to string
bcc string
}

func (op *EmailOutputProvider) buildEmailPayload(subject, body string) string {
Expand Down Expand Up @@ -238,9 +246,13 @@ func (op *EmailOutputProvider) Send(article *model.Article) (bool, error) {
if err := client.Mail(op.from); err != nil {
return false, err
}
tos := strings.Split(op.to, ",")
for _, to := range tos {
if err := client.Rcpt(to); err != nil {
recipients := strings.Split(op.to, ",")
recipients = append(recipients, strings.Split(op.bcc, ",")[:]...)
for _, recipient := range recipients {
if recipient == "" {
continue
}
if err := client.Rcpt(recipient); err != nil {
return false, err
}
}
Expand Down

0 comments on commit 45749a2

Please sign in to comment.