1
0
mirror of https://github.com/containrrr/watchtower.git synced 2024-12-12 09:04:17 +02:00

SMTP port configurable through notification-email-server-port. Defaults to 25.

This commit is contained in:
Fabrizio Steiner 2017-12-27 20:25:49 +01:00
parent 4c63746feb
commit c463241bc7
3 changed files with 12 additions and 1 deletions

View File

@ -193,6 +193,7 @@ To receive notifications by email, the following command-line options, or their
* `--notification-email-from` (env. `WATCHTOWER_NOTIFICATION_EMAIL_FROM`): The e-mail address from which notifications will be sent. * `--notification-email-from` (env. `WATCHTOWER_NOTIFICATION_EMAIL_FROM`): The e-mail address from which notifications will be sent.
* `--notification-email-to` (env. `WATCHTOWER_NOTIFICATION_EMAIL_TO`): The e-mail address to which notifications will be sent. * `--notification-email-to` (env. `WATCHTOWER_NOTIFICATION_EMAIL_TO`): The e-mail address to which notifications will be sent.
* `--notification-email-server` (env. `WATCHTOWER_NOTIFICATION_EMAIL_SERVER`): The SMTP server to send e-mails through. * `--notification-email-server` (env. `WATCHTOWER_NOTIFICATION_EMAIL_SERVER`): The SMTP server to send e-mails through.
* `--notification-email-server-port` (env. `WATCHTOWER_NOTIFICATION_EMAIL_SERVER_PORT`): The port used to connect to the SMTP server to send e-mails through. Defaults to `25`.
* `--notification-email-server-user` (env. `WATCHTOWER_NOTIFICATION_EMAIL_SERVER_USER`): The username to authenticate with the SMTP server with. * `--notification-email-server-user` (env. `WATCHTOWER_NOTIFICATION_EMAIL_SERVER_USER`): The username to authenticate with the SMTP server with.
* `--notification-email-server-password` (env. `WATCHTOWER_NOTIFICATION_EMAIL_SERVER_PASSWORD`): The password to authenticate with the SMTP server with. * `--notification-email-server-password` (env. `WATCHTOWER_NOTIFICATION_EMAIL_SERVER_PASSWORD`): The password to authenticate with the SMTP server with.

View File

@ -111,6 +111,12 @@ func main() {
Usage: "SMTP server to send notification e-mails through", Usage: "SMTP server to send notification e-mails through",
EnvVar: "WATCHTOWER_NOTIFICATION_EMAIL_SERVER", EnvVar: "WATCHTOWER_NOTIFICATION_EMAIL_SERVER",
}, },
cli.IntFlag{
Name: "notification-email-server-port",
Usage: "SMTP server port to send notification e-mails through",
Value: 25,
EnvVar: "WATCHTOWER_NOTIFICATION_EMAIL_SERVER_PORT",
},
cli.StringFlag{ cli.StringFlag{
Name: "notification-email-server-user", Name: "notification-email-server-user",
Usage: "SMTP server user for sending notifications", Usage: "SMTP server user for sending notifications",

View File

@ -6,6 +6,8 @@ import (
"net/smtp" "net/smtp"
"os" "os"
"strconv"
log "github.com/Sirupsen/logrus" log "github.com/Sirupsen/logrus"
"github.com/urfave/cli" "github.com/urfave/cli"
) )
@ -22,6 +24,7 @@ const (
type emailTypeNotifier struct { type emailTypeNotifier struct {
From, To string From, To string
Server, User, Password string Server, User, Password string
Port int
entries []*log.Entry entries []*log.Entry
} }
@ -32,6 +35,7 @@ func newEmailNotifier(c *cli.Context) typeNotifier {
Server: c.GlobalString("notification-email-server"), Server: c.GlobalString("notification-email-server"),
User: c.GlobalString("notification-email-server-user"), User: c.GlobalString("notification-email-server-user"),
Password: c.GlobalString("notification-email-server-password"), Password: c.GlobalString("notification-email-server-password"),
Port: c.GlobalInt("notification-email-server-port"),
} }
log.AddHook(n) log.AddHook(n)
@ -72,7 +76,7 @@ func (e *emailTypeNotifier) sendEntries(entries []*log.Entry) {
msg := e.buildMessage(entries) msg := e.buildMessage(entries)
go func() { go func() {
auth := smtp.PlainAuth("", e.User, e.Password, e.Server) auth := smtp.PlainAuth("", e.User, e.Password, e.Server)
err := smtp.SendMail(e.Server+":25", auth, e.From, []string{e.To}, msg) err := smtp.SendMail(e.Server+":"+strconv.Itoa(e.Port), auth, e.From, []string{e.To}, msg)
if err != nil { if err != nil {
// Use fmt so it doesn't trigger another email. // Use fmt so it doesn't trigger another email.
fmt.Println("Failed to send notification email: ", err) fmt.Println("Failed to send notification email: ", err)