From 8eb84f83b48c4a2e10aeec62a20b977ebb00c4de Mon Sep 17 00:00:00 2001 From: Philipp <151498+eingemaischt@users.noreply.github.com> Date: Tue, 1 Apr 2025 11:02:14 +0000 Subject: [PATCH] Added cfg Parameter to include stdout into mail body instead of a comparison. --- middlewares/mail.go | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/middlewares/mail.go b/middlewares/mail.go index 72a2c621e..f33672f4d 100644 --- a/middlewares/mail.go +++ b/middlewares/mail.go @@ -18,14 +18,15 @@ import ( // MailConfig configuration for the Mail middleware type MailConfig struct { - SMTPHost string `gcfg:"smtp-host" mapstructure:"smtp-host"` - SMTPPort int `gcfg:"smtp-port" mapstructure:"smtp-port"` - SMTPUser string `gcfg:"smtp-user" mapstructure:"smtp-user" json:"-"` - SMTPPassword string `gcfg:"smtp-password" mapstructure:"smtp-password" json:"-"` - SMTPTLSSkipVerify bool `gcfg:"smtp-tls-skip-verify" mapstructure:"smtp-tls-skip-verify"` - EmailTo string `gcfg:"email-to" mapstructure:"email-to"` - EmailFrom string `gcfg:"email-from" mapstructure:"email-from"` - MailOnlyOnError bool `gcfg:"mail-only-on-error" mapstructure:"mail-only-on-error"` + SMTPHost string `gcfg:"smtp-host" mapstructure:"smtp-host"` + SMTPPort int `gcfg:"smtp-port" mapstructure:"smtp-port"` + SMTPUser string `gcfg:"smtp-user" mapstructure:"smtp-user" json:"-"` + SMTPPassword string `gcfg:"smtp-password" mapstructure:"smtp-password" json:"-"` + SMTPTLSSkipVerify bool `gcfg:"smtp-tls-skip-verify" mapstructure:"smtp-tls-skip-verify"` + EmailTo string `gcfg:"email-to" mapstructure:"email-to"` + EmailFrom string `gcfg:"email-from" mapstructure:"email-from"` + MailOnlyOnError bool `gcfg:"mail-only-on-error" mapstructure:"mail-only-on-error"` + IncludeStdoutInBody bool `gcfg:"include-stdout-in-body" mapstructure:"include-stdout-in-body"` } // NewMail returns a Mail middleware if the given configuration is not empty @@ -69,7 +70,12 @@ func (m *Mail) sendMail(ctx *core.Context) error { msg.SetHeader("From", m.from()) msg.SetHeader("To", strings.Split(m.EmailTo, ",")...) msg.SetHeader("Subject", m.subject(ctx)) - msg.SetBody("text/html", m.body(ctx)) + + if m.IncludeStdoutInBody { + msg.SetBody("text/txt", string(ctx.Execution.OutputStream.Bytes())) + } else { + msg.SetBody("text/html", m.body(ctx)) + } base := fmt.Sprintf("%s_%s", ctx.Job.GetName(), ctx.Execution.ID) msg.Attach(base+".stdout.log", gomail.SetCopyFunc(func(w io.Writer) error {