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.
This commit is contained in:
parent
20edd9c7e3
commit
17393400a4
6
main.go
6
main.go
|
@ -79,6 +79,11 @@ func main() {
|
||||||
Usage: "attachment filename",
|
Usage: "attachment filename",
|
||||||
EnvVar: "PLUGIN_ATTACHMENT",
|
EnvVar: "PLUGIN_ATTACHMENT",
|
||||||
},
|
},
|
||||||
|
cli.StringSliceFlag{
|
||||||
|
Name: "attachments",
|
||||||
|
Usage: "attachment filename(s)",
|
||||||
|
EnvVar: "PLUGIN_ATTACHMENTS",
|
||||||
|
},
|
||||||
|
|
||||||
// Drone environment
|
// Drone environment
|
||||||
// Repo
|
// Repo
|
||||||
|
@ -375,6 +380,7 @@ func run(c *cli.Context) error {
|
||||||
Subject: c.String("template.subject"),
|
Subject: c.String("template.subject"),
|
||||||
Body: c.String("template.body"),
|
Body: c.String("template.body"),
|
||||||
Attachment: c.String("attachment"),
|
Attachment: c.String("attachment"),
|
||||||
|
Attachments: c.StringSlice("attachments"),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -89,6 +89,7 @@ type (
|
||||||
Subject string
|
Subject string
|
||||||
Body string
|
Body string
|
||||||
Attachment string
|
Attachment string
|
||||||
|
Attachments []string
|
||||||
}
|
}
|
||||||
|
|
||||||
Plugin struct {
|
Plugin struct {
|
||||||
|
@ -203,6 +204,10 @@ func (p Plugin) Exec() error {
|
||||||
message.Attach(p.Config.Attachment)
|
message.Attach(p.Config.Attachment)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for _, attachment := range p.Config.Attachments {
|
||||||
|
message.Attach(attachment)
|
||||||
|
}
|
||||||
|
|
||||||
if err := gomail.Send(closer, message); err != nil {
|
if err := gomail.Send(closer, message); err != nil {
|
||||||
log.Errorf("Could not send email to %q: %v", recipient, err)
|
log.Errorf("Could not send email to %q: %v", recipient, err)
|
||||||
return err
|
return err
|
||||||
|
|
Loading…
Reference in a new issue