From 17393400a47ed370b837e47b8924683187770271 Mon Sep 17 00:00:00 2001 From: Michael Schlies Date: Fri, 23 Aug 2019 11:06:45 -0500 Subject: [PATCH] Support multiple attachments (#29) * Support multiple attachments * Support single attachment syntax in addition to multiple * Re-add import Goland removed while optimizing imports for me. --- main.go | 6 ++++++ plugin.go | 5 +++++ 2 files changed, 11 insertions(+) diff --git a/main.go b/main.go index 6267123..00356ab 100644 --- a/main.go +++ b/main.go @@ -79,6 +79,11 @@ func main() { Usage: "attachment filename", EnvVar: "PLUGIN_ATTACHMENT", }, + cli.StringSliceFlag{ + Name: "attachments", + Usage: "attachment filename(s)", + EnvVar: "PLUGIN_ATTACHMENTS", + }, // Drone environment // Repo @@ -375,6 +380,7 @@ func run(c *cli.Context) error { Subject: c.String("template.subject"), Body: c.String("template.body"), Attachment: c.String("attachment"), + Attachments: c.StringSlice("attachments"), }, } diff --git a/plugin.go b/plugin.go index 0d7ddea..0557187 100644 --- a/plugin.go +++ b/plugin.go @@ -89,6 +89,7 @@ type ( Subject string Body string Attachment string + Attachments []string } Plugin struct { @@ -203,6 +204,10 @@ func (p Plugin) Exec() error { message.Attach(p.Config.Attachment) } + for _, attachment := range p.Config.Attachments { + message.Attach(attachment) + } + if err := gomail.Send(closer, message); err != nil { log.Errorf("Could not send email to %q: %v", recipient, err) return err