feat: add reply-to header in email notification (#6393)

* feat: add reply-to header to smtp messages

* fix: grpc reply_to_address min 0 and js var name

* fix: add missing translations

* fix merge and linting

---------

Co-authored-by: Livio Spring <livio.a@gmail.com>
This commit is contained in:
Miguel Cabrerizo
2023-08-29 09:08:24 +02:00
committed by GitHub
parent 9b43e28c23
commit fd00ac533a
31 changed files with 307 additions and 120 deletions

View File

@@ -17,9 +17,10 @@ import (
var _ channels.NotificationChannel = (*Email)(nil)
type Email struct {
smtpClient *smtp.Client
senderAddress string
senderName string
smtpClient *smtp.Client
senderAddress string
senderName string
replyToAddress string
}
func InitChannel(ctx context.Context, getSMTPConfig func(ctx context.Context) (*Config, error)) (*Email, error) {
@@ -36,9 +37,10 @@ func InitChannel(ctx context.Context, getSMTPConfig func(ctx context.Context) (*
logging.New().Debug("successfully initialized smtp email channel")
return &Email{
smtpClient: client,
senderName: smtpConfig.FromName,
senderAddress: smtpConfig.From,
smtpClient: client,
senderName: smtpConfig.FromName,
senderAddress: smtpConfig.From,
replyToAddress: smtpConfig.ReplyToAddress,
}, nil
}
@@ -54,6 +56,7 @@ func (email *Email) HandleMessage(message channels.Message) error {
}
emailMsg.SenderEmail = email.senderAddress
emailMsg.SenderName = email.senderName
emailMsg.ReplyToAddress = email.replyToAddress
// To && From
if err := email.smtpClient.Mail(emailMsg.SenderEmail); err != nil {
return caos_errs.ThrowInternalf(err, "EMAIL-s3is3", "could not set sender: %v", emailMsg.SenderEmail)

View File

@@ -1,10 +1,11 @@
package smtp
type Config struct {
SMTP SMTP
Tls bool
From string
FromName string
SMTP SMTP
Tls bool
From string
FromName string
ReplyToAddress string
}
type SMTP struct {

View File

@@ -19,9 +19,10 @@ func (n *NotificationQueries) GetSMTPConfig(ctx context.Context) (*smtp.Config,
return nil, err
}
return &smtp.Config{
From: config.SenderAddress,
FromName: config.SenderName,
Tls: config.TLS,
From: config.SenderAddress,
FromName: config.SenderName,
ReplyToAddress: config.ReplyToAddress,
Tls: config.TLS,
SMTP: smtp.SMTP{
Host: config.Host,
User: config.User,

View File

@@ -23,6 +23,7 @@ type Email struct {
CC []string
SenderEmail string
SenderName string
ReplyToAddress string
Subject string
Content string
TriggeringEvent eventstore.Event
@@ -35,6 +36,9 @@ func (msg *Email) GetContent() (string, error) {
from = fmt.Sprintf("%s <%s>", msg.SenderName, msg.SenderEmail)
}
headers["From"] = from
if msg.ReplyToAddress != "" {
headers["Reply-to"] = msg.ReplyToAddress
}
headers["Return-Path"] = msg.SenderEmail
headers["To"] = strings.Join(msg.Recipients, ", ")
headers["Cc"] = strings.Join(msg.CC, ", ")