0
0
Fork 0
mirror of https://github.com/crazy-max/diun.git synced 2025-04-10 22:00:13 +00:00

Allow multi recipients for email notifier ()

Co-authored-by: CrazyMax <crazy-max@users.noreply.github.com>
This commit is contained in:
CrazyMax 2021-08-19 21:51:52 +02:00 committed by GitHub
parent bbb00c0d51
commit 21f5d0839a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 34 additions and 23 deletions
docs
config
notif
internal

View file

@ -52,7 +52,9 @@ You can override this using the [`--config` flag or `CONFIG` env var with `serve
ssl: false
insecureSkipVerify: false
from: diun@example.com
to: webmaster@example.com
to:
- webmaster@example.com
- me@example.com
rocketchat:
endpoint: http://rocket.foo.com:3000
channel: "#general"

View file

@ -13,7 +13,9 @@ Notifications can be sent through SMTP.
ssl: false
insecureSkipVerify: false
from: diun@example.com
to: webmaster@example.com
to:
- webmaster@example.com
- me@example.com
templateTitle: "{{ .Entry.Image }} released"
templateBody: |
Docker tag {{ .Entry.Image }} which you subscribed to through {{ .Entry.Provider }} provider has been released.
@ -31,7 +33,7 @@ Notifications can be sent through SMTP.
| `password` | | SMTP password |
| `passwordFile` | | Use content of secret file as SMTP password if `password` not defined |
| `from`[^1] | | Sender email address |
| `to`[^1] | | Recipient email address |
| `to`[^1] | | List of recipients email addresses |
| `templateTitle`[^1] | See [below](#default-templatetitle) | [Notification template](../faq.md#notification-template) for message title |
| `templateBody`[^1] | See [below](#default-templatebody) | [Notification template](../faq.md#notification-template) for message body |
@ -46,7 +48,7 @@ Notifications can be sent through SMTP.
* `DIUN_NOTIF_MAIL_PASSWORD`
* `DIUN_NOTIF_MAIL_PASSWORDFILE`
* `DIUN_NOTIF_MAIL_FROM`
* `DIUN_NOTIF_MAIL_TO`
* `DIUN_NOTIF_MAIL_TO` (comma separated)
* `DIUN_NOTIF_MAIL_TEMPLATETITLE`
* `DIUN_NOTIF_MAIL_TEMPLATEBODY`

View file

@ -95,8 +95,11 @@ func TestLoadFile(t *testing.T) {
InsecureSkipVerify: utl.NewFalse(),
LocalName: "localhost",
From: "diun@example.com",
To: "webmaster@example.com",
TemplateTitle: model.NotifDefaultTemplateTitle,
To: []string{
"webmaster@example.com",
"me@example.com",
},
TemplateTitle: model.NotifDefaultTemplateTitle,
TemplateBody: `Docker tag {{ if .Entry.Image.HubLink }}[**{{ .Entry.Image }}**]({{ .Entry.Image.HubLink }}){{ else }}**{{ .Entry.Image }}**{{ end }}
which you subscribed to through {{ .Entry.Provider }} provider has been {{ if (eq .Entry.Status "new") }}newly added{{ else }}updated{{ end }}.
@ -418,8 +421,10 @@ func TestLoadMixed(t *testing.T) {
InsecureSkipVerify: utl.NewTrue(),
LocalName: "foo.com",
From: "diun@foo.com",
To: "webmaster@foo.com",
TemplateTitle: model.NotifDefaultTemplateTitle,
To: []string{
"webmaster@foo.com",
},
TemplateTitle: model.NotifDefaultTemplateTitle,
TemplateBody: `Docker tag {{ if .Entry.Image.HubLink }}[**{{ .Entry.Image }}**]({{ .Entry.Image.HubLink }}){{ else }}**{{ .Entry.Image }}**{{ end }}
which you subscribed to through {{ .Entry.Provider }} provider has been {{ if (eq .Entry.Status "new") }}newly added{{ else }}updated{{ end }}.

View file

@ -37,7 +37,9 @@ notif:
ssl: false
insecureSkipVerify: false
from: diun@example.com
to: webmaster@example.com
to:
- webmaster@example.com
- me@example.com
templateBody: |
Docker tag {{ if .Entry.Image.HubLink }}[**{{ .Entry.Image }}**]({{ .Entry.Image.HubLink }}){{ else }}**{{ .Entry.Image }}**{{ end }}
which you subscribed to through {{ .Entry.Provider }} provider has been {{ if (eq .Entry.Status "new") }}newly added{{ else }}updated{{ end }}.

View file

@ -17,19 +17,19 @@ Need help, or have questions? Go to {{ .Meta.URL }} and leave an issue.`
// NotifMail holds mail notification configuration details
type NotifMail struct {
Host string `yaml:"host,omitempty" json:"host,omitempty" validate:"required"`
Port int `yaml:"port,omitempty" json:"port,omitempty" validate:"required,min=1"`
SSL *bool `yaml:"ssl,omitempty" json:"ssl,omitempty" validate:"required"`
InsecureSkipVerify *bool `yaml:"insecureSkipVerify,omitempty" json:"insecureSkipVerify,omitempty" validate:"required"`
LocalName string `yaml:"localName,omitempty" json:"localName,omitempty" validate:"omitempty"`
Username string `yaml:"username,omitempty" json:"username,omitempty" validate:"omitempty"`
UsernameFile string `yaml:"usernameFile,omitempty" json:"usernameFile,omitempty" validate:"omitempty,file"`
Password string `yaml:"password,omitempty" json:"password,omitempty" validate:"omitempty"`
PasswordFile string `yaml:"passwordFile,omitempty" json:"passwordFile,omitempty" validate:"omitempty,file"`
From string `yaml:"from,omitempty" json:"from,omitempty" validate:"required,email"`
To string `yaml:"to,omitempty" json:"to,omitempty" validate:"required,email"`
TemplateTitle string `yaml:"templateTitle,omitempty" json:"templateTitle,omitempty" validate:"required"`
TemplateBody string `yaml:"templateBody,omitempty" json:"templateBody,omitempty" validate:"required"`
Host string `yaml:"host,omitempty" json:"host,omitempty" validate:"required"`
Port int `yaml:"port,omitempty" json:"port,omitempty" validate:"required,min=1"`
SSL *bool `yaml:"ssl,omitempty" json:"ssl,omitempty" validate:"required"`
InsecureSkipVerify *bool `yaml:"insecureSkipVerify,omitempty" json:"insecureSkipVerify,omitempty" validate:"required"`
LocalName string `yaml:"localName,omitempty" json:"localName,omitempty" validate:"omitempty"`
Username string `yaml:"username,omitempty" json:"username,omitempty" validate:"omitempty"`
UsernameFile string `yaml:"usernameFile,omitempty" json:"usernameFile,omitempty" validate:"omitempty,file"`
Password string `yaml:"password,omitempty" json:"password,omitempty" validate:"omitempty"`
PasswordFile string `yaml:"passwordFile,omitempty" json:"passwordFile,omitempty" validate:"omitempty,file"`
From string `yaml:"from,omitempty" json:"from,omitempty" validate:"required,email"`
To []string `yaml:"to,omitempty" json:"to,omitempty" validate:"required"`
TemplateTitle string `yaml:"templateTitle,omitempty" json:"templateTitle,omitempty" validate:"required"`
TemplateBody string `yaml:"templateBody,omitempty" json:"templateBody,omitempty" validate:"required"`
}
// GetDefaults gets the default values

View file

@ -89,7 +89,7 @@ func (c *Client) Send(entry model.NotifEntry) error {
mailMessage := gomail.NewMessage()
mailMessage.SetHeader("From", fmt.Sprintf("%s <%s>", c.meta.Name, c.cfg.From))
mailMessage.SetHeader("To", c.cfg.To)
mailMessage.SetHeader("To", c.cfg.To...)
mailMessage.SetHeader("Subject", string(title))
mailMessage.SetBody("text/plain", textpart)
mailMessage.AddAlternative("text/html", htmlpart)