diff --git a/notification-eventmanager/e2e/main_test.go b/notification-eventmanager/e2e/main_test.go index 1ba38c71d..f397007ba 100644 --- a/notification-eventmanager/e2e/main_test.go +++ b/notification-eventmanager/e2e/main_test.go @@ -628,7 +628,7 @@ func TestReceiver_Email(t *testing.T) { email := <-emails assert.NotNil(t, email) - assert.Equal(t, "", email.Sender) + assert.Equal(t, "", email.Sender) } func TestReceiver_RemoveAllEventTypes(t *testing.T) { diff --git a/notification-sender/cmd/sender/main.go b/notification-sender/cmd/sender/main.go index 3c1ea9e49..812898c92 100644 --- a/notification-sender/cmd/sender/main.go +++ b/notification-sender/cmd/sender/main.go @@ -39,6 +39,7 @@ func main() { stackdriverLogID string emailURI string emailFrom string + emailReplyTo string ) flag.StringVar(&logLevel, "log.level", "info", "Logging level to use: debug | info | warn | error") @@ -51,7 +52,8 @@ func main() { // upper and lower case alphanumeric characters, forward-slash, underscore, hyphen, and period. flag.StringVar(&stackdriverLogID, "stackdriverLogID", "WeaveCloud", "LogID for stackdriver notifications") flag.StringVar(&emailURI, "emailURI", "", "uri of smtp server to send email through, of the format: smtp://username:password@hostname:port. Email-uri must be provided. For local development, you can set this to: log://, which will log all emails.") - flag.StringVar(&emailFrom, "emailFrom", "Weave Cloud ", "From address for emails.") + flag.StringVar(&emailFrom, "emailFrom", "Weave Cloud ", "From address for emails.") + flag.StringVar(&emailReplyTo, "emailReplyTo", "Weave Cloud ", "Reply-To for emails.") flag.Parse() @@ -60,13 +62,14 @@ func main() { return } - if err := sender.ValidateEmailSender(emailURI, emailFrom); err != nil { + if err := sender.ValidateEmailSender(emailURI, emailFrom, emailReplyTo); err != nil { log.Fatalf("cannot validate email sender (URI: %s, From: %s), error: %s", emailURI, emailFrom, err) } es := &sender.EmailSender{ - URI: emailURI, - From: emailFrom, + URI: emailURI, + From: emailFrom, + ReplyTo: emailReplyTo, } ss := &sender.SlackSender{ diff --git a/notification-sender/email.go b/notification-sender/email.go index c38bb30a8..52f442df4 100644 --- a/notification-sender/email.go +++ b/notification-sender/email.go @@ -30,15 +30,16 @@ const ( // EmailSender contains creds to send emails type EmailSender struct { - URI string - From string + URI string + From string + ReplyTo string } -func waitForMailService(uri, from string) error { +func waitForMailService(uri, from, replyto string) error { deadline := time.Now().Add(timeout) var err error for tries := 0; time.Now().Before(deadline); tries++ { - err = parseAndSend(uri, from, []string{"weaveworkstest@gmail.com"}, "Email sender validation", from) + err = parseAndSend(uri, from, replyto, []string{"weaveworkstest@gmail.com"}, "Email sender validation", from) if err == nil { return nil } @@ -49,8 +50,8 @@ func waitForMailService(uri, from string) error { } // ValidateEmailSender validates uri and from for email sender by sending test email -func ValidateEmailSender(uri, from string) error { - if err := waitForMailService(uri, from); err != nil { +func ValidateEmailSender(uri, from, replyto string) error { + if err := waitForMailService(uri, from, replyto); err != nil { return errors.Wrap(err, "email sender validation failed") } log.Debug("email sender validated successfully") @@ -85,14 +86,14 @@ func (es *EmailSender) Send(_ context.Context, addr json.RawMessage, notif types } addresses := strings.Split(addrStr, EmailSeparator) - if err := parseAndSend(es.URI, es.From, addresses, notifData.Subject, notifData.Body); err != nil { + if err := parseAndSend(es.URI, es.From, es.ReplyTo, addresses, notifData.Subject, notifData.Body); err != nil { return errors.Wrap(err, "cannot parse and send email") } return nil } -func parseAndSend(uri, from string, addresses []string, subject, body string) error { +func parseAndSend(uri, from string, replyto string, addresses []string, subject, body string) error { u, err := url.Parse(uri) if err != nil { return errors.Wrapf(err, "cannot parse email URI %s", uri) @@ -127,6 +128,7 @@ func parseAndSend(uri, from string, addresses []string, subject, body string) er m.SetHeader("From", from) m.SetHeader("To", formatted...) m.SetHeader("Subject", subject) + m.SetHeader("Reply-To", replyto) m.SetBody("text/html", body) uid := uuid.New() m.SetHeader("X-Entity-Ref-ID", uid.String())