feat(notifications): add support for custom sender name in email notifications

pull/2094/head
Jan Rundshagen 9 months ago committed by Jan O. Rundshagen
parent a44622770b
commit 149af7827b

@ -246,6 +246,12 @@ func RegisterNotificationFlags(rootCmd *cobra.Command) {
envString("WATCHTOWER_NOTIFICATION_EMAIL_FROM"), envString("WATCHTOWER_NOTIFICATION_EMAIL_FROM"),
"Address to send notification emails from") "Address to send notification emails from")
flags.StringP(
"notification-email-from-name",
"",
envString("WATCHTOWER_NOTIFICATION_EMAIL_FROM_NAME"),
"Name to send notification emails from")
flags.StringP( flags.StringP(
"notification-email-to", "notification-email-to",
"", "",
@ -425,6 +431,7 @@ func SetDefaults() {
viper.SetDefault("WATCHTOWER_TIMEOUT", time.Second*10) viper.SetDefault("WATCHTOWER_TIMEOUT", time.Second*10)
viper.SetDefault("WATCHTOWER_NOTIFICATIONS", []string{}) viper.SetDefault("WATCHTOWER_NOTIFICATIONS", []string{})
viper.SetDefault("WATCHTOWER_NOTIFICATIONS_LEVEL", "info") viper.SetDefault("WATCHTOWER_NOTIFICATIONS_LEVEL", "info")
viper.SetDefault("WATCHTOWER_NOTIFICATION_EMAIL_FROM", "Watchtower")
viper.SetDefault("WATCHTOWER_NOTIFICATION_EMAIL_SERVER_PORT", 25) viper.SetDefault("WATCHTOWER_NOTIFICATION_EMAIL_SERVER_PORT", 25)
viper.SetDefault("WATCHTOWER_NOTIFICATION_EMAIL_SUBJECTTAG", "") viper.SetDefault("WATCHTOWER_NOTIFICATION_EMAIL_SUBJECTTAG", "")
viper.SetDefault("WATCHTOWER_NOTIFICATION_SLACK_IDENTIFIER", "watchtower") viper.SetDefault("WATCHTOWER_NOTIFICATION_SLACK_IDENTIFIER", "watchtower")

@ -15,7 +15,7 @@ const (
) )
type emailTypeNotifier struct { type emailTypeNotifier struct {
From, To string From, FromName, To string
Server, User, Password string Server, User, Password string
Port int Port int
tlsSkipVerify bool tlsSkipVerify bool
@ -27,6 +27,7 @@ func newEmailNotifier(c *cobra.Command) t.ConvertibleNotifier {
flags := c.Flags() flags := c.Flags()
from, _ := flags.GetString("notification-email-from") from, _ := flags.GetString("notification-email-from")
fromName, _ := flags.GetString("notification-email-from-name")
to, _ := flags.GetString("notification-email-to") to, _ := flags.GetString("notification-email-to")
server, _ := flags.GetString("notification-email-server") server, _ := flags.GetString("notification-email-server")
user, _ := flags.GetString("notification-email-server-user") user, _ := flags.GetString("notification-email-server-user")
@ -38,6 +39,7 @@ func newEmailNotifier(c *cobra.Command) t.ConvertibleNotifier {
n := &emailTypeNotifier{ n := &emailTypeNotifier{
entries: []*log.Entry{}, entries: []*log.Entry{},
From: from, From: from,
FromName: fromName,
To: to, To: to,
Server: server, Server: server,
User: user, User: user,
@ -53,7 +55,7 @@ func newEmailNotifier(c *cobra.Command) t.ConvertibleNotifier {
func (e *emailTypeNotifier) GetURL(c *cobra.Command) (string, error) { func (e *emailTypeNotifier) GetURL(c *cobra.Command) (string, error) {
conf := &shoutrrrSmtp.Config{ conf := &shoutrrrSmtp.Config{
FromAddress: e.From, FromAddress: e.From,
FromName: "Watchtower", FromName: e.FromName,
ToAddresses: []string{e.To}, ToAddresses: []string{e.To},
Port: uint16(e.Port), Port: uint16(e.Port),
Host: e.Server, Host: e.Server,

Loading…
Cancel
Save