Merge pull request #42 from s00500/master
Add options to load recipients from file (#41)
This commit is contained in:
commit
e861696b04
1
DOCS.md
1
DOCS.md
|
@ -10,6 +10,7 @@ You can configure the plugin using the following parameters:
|
|||
* **password** - SMTP password
|
||||
* **skip_verify** - Skip verification of SSL certificates, defaults to `false`
|
||||
* **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`
|
||||
* **subject** - The subject line template
|
||||
* **body** - The email body template
|
||||
|
|
6
main.go
6
main.go
|
@ -56,6 +56,11 @@ func main() {
|
|||
Usage: "skip tls 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{
|
||||
Name: "recipients",
|
||||
Usage: "recipient addresses",
|
||||
|
@ -386,6 +391,7 @@ func run(c *cli.Context) error {
|
|||
Password: c.String("password"),
|
||||
SkipVerify: c.Bool("skip.verify"),
|
||||
Recipients: c.StringSlice("recipients"),
|
||||
RecipientsFile: c.String("recipients.file"),
|
||||
RecipientsOnly: c.Bool("recipients.only"),
|
||||
Subject: c.String("template.subject"),
|
||||
Body: c.String("template.body"),
|
||||
|
|
21
plugin.go
21
plugin.go
|
@ -1,13 +1,15 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"crypto/tls"
|
||||
"os"
|
||||
|
||||
log "github.com/Sirupsen/logrus"
|
||||
"github.com/aymerick/douceur/inliner"
|
||||
"github.com/drone/drone-go/template"
|
||||
"github.com/jaytaylor/html2text"
|
||||
"gopkg.in/gomail.v2"
|
||||
"os"
|
||||
)
|
||||
|
||||
type (
|
||||
|
@ -86,12 +88,13 @@ type (
|
|||
Password string
|
||||
SkipVerify bool
|
||||
Recipients []string
|
||||
RecipientsFile string
|
||||
RecipientsOnly bool
|
||||
Subject string
|
||||
Body string
|
||||
Attachment string
|
||||
Attachments []string
|
||||
ClientHostname string
|
||||
ClientHostname string
|
||||
}
|
||||
|
||||
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 == "" {
|
||||
dialer = &gomail.Dialer{Host: p.Config.Host, Port: p.Config.Port}
|
||||
} else {
|
||||
|
@ -134,7 +149,7 @@ func (p Plugin) Exec() error {
|
|||
if p.Config.SkipVerify {
|
||||
dialer.TLSConfig = &tls.Config{InsecureSkipVerify: true}
|
||||
}
|
||||
dialer.LocalName = p.Config.ClientHostname
|
||||
dialer.LocalName = p.Config.ClientHostname
|
||||
|
||||
closer, err := dialer.Dial()
|
||||
if err != nil {
|
||||
|
|
Loading…
Reference in a new issue