Add options to load recipients from file
Signed-off-by: Lukas Bachschwell <lukas@lbsfilm.at>
This commit is contained in:
parent
28bc16668a
commit
c139365a67
1
DOCS.md
1
DOCS.md
|
@ -10,6 +10,7 @@ You can configure the plugin using the following parameters:
|
||||||
* **password** - SMTP password
|
* **password** - SMTP password
|
||||||
* **skip_verify** - Skip verification of SSL certificates, defaults to `false`
|
* **skip_verify** - Skip verification of SSL certificates, defaults to `false`
|
||||||
* **recipients** - List of recipients to send this mail to (besides the commit author)
|
* **recipients** - List of recipients to send this mail to (besides the commit author)
|
||||||
|
* **recipients_file** - Filename to load additional recipients from (textfile with one email per line) (besides the commit author)
|
||||||
* **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
|
||||||
|
|
6
main.go
6
main.go
|
@ -56,6 +56,11 @@ func main() {
|
||||||
Usage: "skip tls verify",
|
Usage: "skip tls verify",
|
||||||
EnvVar: "PLUGIN_SKIP_VERIFY",
|
EnvVar: "PLUGIN_SKIP_VERIFY",
|
||||||
},
|
},
|
||||||
|
cli.StringFlag{
|
||||||
|
Name: "recipients.file",
|
||||||
|
Usage: "file to read recipients from",
|
||||||
|
EnvVar: "EMAIL_RECIPIENTS_FILE,PLUGIN_RECIPIENTS_FILE",
|
||||||
|
},
|
||||||
cli.StringSliceFlag{
|
cli.StringSliceFlag{
|
||||||
Name: "recipients",
|
Name: "recipients",
|
||||||
Usage: "recipient addresses",
|
Usage: "recipient addresses",
|
||||||
|
@ -386,6 +391,7 @@ func run(c *cli.Context) error {
|
||||||
Password: c.String("password"),
|
Password: c.String("password"),
|
||||||
SkipVerify: c.Bool("skip.verify"),
|
SkipVerify: c.Bool("skip.verify"),
|
||||||
Recipients: c.StringSlice("recipients"),
|
Recipients: c.StringSlice("recipients"),
|
||||||
|
RecipientsFile: c.String("recipients.file"),
|
||||||
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"),
|
||||||
|
|
21
plugin.go
21
plugin.go
|
@ -1,13 +1,15 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bufio"
|
||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
|
"os"
|
||||||
|
|
||||||
log "github.com/Sirupsen/logrus"
|
log "github.com/Sirupsen/logrus"
|
||||||
"github.com/aymerick/douceur/inliner"
|
"github.com/aymerick/douceur/inliner"
|
||||||
"github.com/drone/drone-go/template"
|
"github.com/drone/drone-go/template"
|
||||||
"github.com/jaytaylor/html2text"
|
"github.com/jaytaylor/html2text"
|
||||||
"gopkg.in/gomail.v2"
|
"gopkg.in/gomail.v2"
|
||||||
"os"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type (
|
type (
|
||||||
|
@ -86,12 +88,13 @@ type (
|
||||||
Password string
|
Password string
|
||||||
SkipVerify bool
|
SkipVerify bool
|
||||||
Recipients []string
|
Recipients []string
|
||||||
|
RecipientsFile string
|
||||||
RecipientsOnly bool
|
RecipientsOnly bool
|
||||||
Subject string
|
Subject string
|
||||||
Body string
|
Body string
|
||||||
Attachment string
|
Attachment string
|
||||||
Attachments []string
|
Attachments []string
|
||||||
ClientHostname string
|
ClientHostname string
|
||||||
}
|
}
|
||||||
|
|
||||||
Plugin struct {
|
Plugin struct {
|
||||||
|
@ -126,6 +129,18 @@ func (p Plugin) Exec() error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if p.Config.RecipientsFile != "" {
|
||||||
|
f, err := os.Open(p.Config.RecipientsFile)
|
||||||
|
if err == nil {
|
||||||
|
scanner := bufio.NewScanner(f)
|
||||||
|
for scanner.Scan() {
|
||||||
|
p.Config.Recipients = append(p.Config.Recipients, scanner.Text())
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
log.Errorf("Could not open RecipientsFile %s: %v", p.Config.RecipientsFile, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if p.Config.Username == "" && p.Config.Password == "" {
|
if p.Config.Username == "" && p.Config.Password == "" {
|
||||||
dialer = &gomail.Dialer{Host: p.Config.Host, Port: p.Config.Port}
|
dialer = &gomail.Dialer{Host: p.Config.Host, Port: p.Config.Port}
|
||||||
} else {
|
} else {
|
||||||
|
@ -134,7 +149,7 @@ func (p Plugin) Exec() error {
|
||||||
if p.Config.SkipVerify {
|
if p.Config.SkipVerify {
|
||||||
dialer.TLSConfig = &tls.Config{InsecureSkipVerify: true}
|
dialer.TLSConfig = &tls.Config{InsecureSkipVerify: true}
|
||||||
}
|
}
|
||||||
dialer.LocalName = p.Config.ClientHostname
|
dialer.LocalName = p.Config.ClientHostname
|
||||||
|
|
||||||
closer, err := dialer.Dial()
|
closer, err := dialer.Dial()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in a new issue