diff --git a/DOCS.md b/DOCS.md index 3289ef9..ee2f7f6 100644 --- a/DOCS.md +++ b/DOCS.md @@ -3,7 +3,8 @@ Use the Email plugin for sending build status notifications via email. ## Config You can configure the plugin using the following parameters: -* **from** - Send notifications from this address +* **from.address** - Send notifications from this address +* **from.name** - Notifications sender name * **host** - SMTP server host * **port** - SMTP server port, defaults to `587` * **username** - SMTP username @@ -29,7 +30,8 @@ steps: - name: notify image: drillster/drone-email settings: - from: noreply@github.com + from.address: noreply@github.com + from.name: John Smith host: smtp.mailgun.org username: octocat password: 12345 @@ -45,7 +47,7 @@ steps: - name: notify: image: drillster/drone-email settings: - from: noreply@github.com + from.address: noreply@github.com host: smtp.mailgun.org + username: + from_secret: email_username @@ -91,7 +93,7 @@ steps: - name: notify image: drillster/drone-email settings: - from: noreply@github.com + from.address: noreply@github.com host: smtp.mailgun.org username: octocat password: 12345 diff --git a/README.md b/README.md index b4a3154..777f5f9 100644 --- a/README.md +++ b/README.md @@ -42,7 +42,8 @@ Execute from the working directory: ```sh docker run --rm \ - -e PLUGIN_FROM=drone@test.test \ + -e PLUGIN_FROM_ADDRESS=drone@test.test \ + -e PLUGIN_FROM_NAME="John Smith" \ -e PLUGIN_HOST=smtp.test.test \ -e PLUGIN_USERNAME=drone \ -e PLUGIN_PASSWORD=test \ diff --git a/main.go b/main.go index e96fd59..1210307 100644 --- a/main.go +++ b/main.go @@ -30,6 +30,16 @@ func main() { Usage: "from address", EnvVar: "PLUGIN_FROM", }, + cli.StringFlag{ + Name: "from.address", + Usage: "from address", + EnvVar: "PLUGIN_FROM_ADDRESS", + }, + cli.StringFlag{ + Name: "from.name", + Usage: "from name", + EnvVar: "PLUGIN_FROM_NAME", + }, cli.StringFlag{ Name: "host", Usage: "smtp host", @@ -325,6 +335,12 @@ func main() { } func run(c *cli.Context) error { + + var fromAddress string = c.String("from") + if fromAddress == "" { + fromAddress = c.String("from.address") + } + plugin := Plugin{ Repo: Repo{ FullName: c.String("repo.fullName"), @@ -384,7 +400,8 @@ func run(c *cli.Context) error { PullRequest: c.Int("pullRequest"), DeployTo: c.String("deployTo"), Config: Config{ - From: c.String("from"), + FromAddress: fromAddress, + FromName: c.String("from.name"), Host: c.String("host"), Port: c.Int("port"), Username: c.String("username"), diff --git a/plugin.go b/plugin.go index 5a4045c..9057941 100644 --- a/plugin.go +++ b/plugin.go @@ -81,7 +81,8 @@ type ( } Config struct { - From string + FromAddress string + FromName string Host string Port int Username string @@ -212,7 +213,7 @@ func (p Plugin) Exec() error { if len(recipient) == 0 { continue } - message.SetHeader("From", p.Config.From) + message.SetAddressHeader("From", p.Config.FromAddress, p.Config.FromName) message.SetAddressHeader("To", recipient, "") message.SetHeader("Subject", subject) message.AddAlternative("text/plain", plainBody)