Add ability to attach a file to the sent mail(s)
This commit is contained in:
parent
f8088a6429
commit
982dc51fc6
1
DOCS.md
1
DOCS.md
|
@ -13,6 +13,7 @@ You can configure the plugin using the following parameters:
|
||||||
* **recipients_only** - Do not send mails to the commit author, but only to **recipients**, defaults to `false`
|
* **recipients_only** - Do not send mails to the commit author, but only to **recipients**, defaults to `false`
|
||||||
* **subject** - The subject line template
|
* **subject** - The subject line template
|
||||||
* **body** - The email body template
|
* **body** - The email body template
|
||||||
|
* **attachment** - An optional file to attach to the sent mail(s), can be an absolute path or relative to the working directory.
|
||||||
|
|
||||||
## Example
|
## Example
|
||||||
|
|
||||||
|
|
6
main.go
6
main.go
|
@ -74,6 +74,11 @@ func main() {
|
||||||
Usage: "body template",
|
Usage: "body template",
|
||||||
EnvVar: "PLUGIN_BODY",
|
EnvVar: "PLUGIN_BODY",
|
||||||
},
|
},
|
||||||
|
cli.StringFlag{
|
||||||
|
Name: "attachment",
|
||||||
|
Usage: "attachment filename",
|
||||||
|
EnvVar: "PLUGIN_ATTACHMENT",
|
||||||
|
},
|
||||||
|
|
||||||
// Drone environment
|
// Drone environment
|
||||||
// Repo
|
// Repo
|
||||||
|
@ -369,6 +374,7 @@ func run(c *cli.Context) error {
|
||||||
RecipientsOnly: c.Bool("recipients.only"),
|
RecipientsOnly: c.Bool("recipients.only"),
|
||||||
Subject: c.String("template.subject"),
|
Subject: c.String("template.subject"),
|
||||||
Body: c.String("template.body"),
|
Body: c.String("template.body"),
|
||||||
|
Attachment: c.String("attachment"),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -88,6 +88,7 @@ type (
|
||||||
RecipientsOnly bool
|
RecipientsOnly bool
|
||||||
Subject string
|
Subject string
|
||||||
Body string
|
Body string
|
||||||
|
Attachment string
|
||||||
}
|
}
|
||||||
|
|
||||||
Plugin struct {
|
Plugin struct {
|
||||||
|
@ -195,6 +196,10 @@ func (p Plugin) Exec() error {
|
||||||
message.AddAlternative("text/plain", plainBody)
|
message.AddAlternative("text/plain", plainBody)
|
||||||
message.AddAlternative("text/html", html)
|
message.AddAlternative("text/html", html)
|
||||||
|
|
||||||
|
if p.Config.Attachment != "" {
|
||||||
|
message.Attach(p.Config.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