Skip to content

Commit

Permalink
feat(alerting/email): Send table in html (pre), VERSION v0.7.5
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejsika committed May 26, 2021
1 parent e950a16 commit bd87a7c
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions alerting/backend_email/backend_email.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,21 @@ func (config *AlertEmail) Validate() error {
func sendMail(config BackendEmail, to string, subject string, body string) error {
finalSubject := "[tergum] " + subject
finalBody := body + "\n\n--\ntergum"
err := gosendmail.GoSendMail(
rawMessage := []byte("To: " + to + "\r\n" +
"From: " + config.Email + "\r\n" +
"Subject: " + finalSubject + "\r\n" +
"MIME-Version: 1.0\r\n" +
"Content-Type: text/html\r\n" +
"Content-Disposition: inline\r\n" +
"\r\n" +
finalBody + "\r\n")
err := gosendmail.GoRawSendMail(
config.SmtpHost,
config.SmtpPort,
config.Email,
config.Password,
to,
finalSubject,
finalBody,
rawMessage,
)
return err
}
Expand All @@ -58,12 +65,18 @@ func SendAlertEmail(
globalLog backup_log.BackupGlobalLog,
) error {
table := backup_log.GlobalLogToString(globalLog)
body := `
<html>
<body>
<pre style="font: monospace">` + table + `</pre>
</body>
</html>`
for _, email := range alert.Emails {
err := sendMail(
backendConfig,
email,
"Backup Summary -- "+globalLog.SuccessString(),
table,
body,
)
if err != nil {
fmt.Fprintf(os.Stderr, "%s\n", err.Error())
Expand Down

0 comments on commit bd87a7c

Please sign in to comment.