parent
5fae49a971
commit
07bf0cfe2f
|
@ -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"
|
||||||
|
}
|
|
@ -20,6 +20,7 @@ import (
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
var stdoutMu sync.Mutex
|
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, "To: %s\n", strings.Join(to, ", "))
|
||||||
fmt.Fprintf(stdin, "Subject: [certspotter] %s\n", notif.Summary())
|
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, "Mime-Version: 1.0\n")
|
||||||
fmt.Fprintf(stdin, "Content-Type: text/plain; charset=US-ASCII\n")
|
fmt.Fprintf(stdin, "Content-Type: text/plain; charset=US-ASCII\n")
|
||||||
fmt.Fprintf(stdin, "X-Mailer: certspotter\n")
|
fmt.Fprintf(stdin, "X-Mailer: certspotter\n")
|
||||||
|
|
Loading…
Reference in New Issue