diff --git a/monitor/mailutils.go b/monitor/mailutils.go new file mode 100644 index 0000000..150fd46 --- /dev/null +++ b/monitor/mailutils.go @@ -0,0 +1,25 @@ +// Copyright (C) 2023 Opsmate, Inc. +// +// This Source Code Form is subject to the terms of the Mozilla +// Public License, v. 2.0. If a copy of the MPL was not distributed +// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. +// +// This software is distributed WITHOUT A WARRANTY OF ANY KIND. +// See the Mozilla Public License for details. + +package monitor + +import ( + "crypto/rand" + "encoding/hex" +) + +const mailDateFormat = "Mon, 2 Jan 2006 15:04:05 -0700" + +func generateMessageID() string { + var randomBytes [16]byte + if _, err := rand.Read(randomBytes[:]); err != nil { + panic(err) + } + return hex.EncodeToString(randomBytes[:]) + "@selfhosted.certspotter.org" +} diff --git a/monitor/notify.go b/monitor/notify.go index f2c51fb..5936e01 100644 --- a/monitor/notify.go +++ b/monitor/notify.go @@ -20,6 +20,7 @@ import ( "path/filepath" "strings" "sync" + "time" ) var stdoutMu sync.Mutex @@ -73,6 +74,8 @@ func sendEmail(ctx context.Context, to []string, notif notification) error { fmt.Fprintf(stdin, "To: %s\n", strings.Join(to, ", ")) fmt.Fprintf(stdin, "Subject: [certspotter] %s\n", notif.Summary()) + fmt.Fprintf(stdin, "Date: %s\n", time.Now().Format(mailDateFormat)) + fmt.Fprintf(stdin, "Message-ID: <%s>\n", generateMessageID()) fmt.Fprintf(stdin, "Mime-Version: 1.0\n") fmt.Fprintf(stdin, "Content-Type: text/plain; charset=US-ASCII\n") fmt.Fprintf(stdin, "X-Mailer: certspotter\n")