Skip to content

Commit

Permalink
Respect $EMAIL when sending emails
Browse files Browse the repository at this point in the history
Envelope sender and RFC5322.From address are set to $EMAIL if it's non-empty.

Requested in SSLMate#87
  • Loading branch information
AGWA authored and fritterhoff committed Jun 9, 2024
1 parent 68b3a12 commit 97b9479
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
5 changes: 5 additions & 0 deletions man/certspotter.md
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,11 @@ and non-zero when a serious error occurs.
: Directory from which any configuration, such as the watch list, is read.
Defaults to `~/.certspotter`.

`EMAIL`

: Email address from which to send emails. If not set, certspotter lets sendmail pick
the address.

`HTTPS_PROXY`

: URL of proxy server for making HTTPS requests. `http://`, `https://`, and
Expand Down
11 changes: 10 additions & 1 deletion monitor/notify.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ func sendEmail(ctx context.Context, to []string, notif *notification) error {
stdin := new(bytes.Buffer)
stderr := new(bytes.Buffer)

from := os.Getenv("EMAIL")

if from != "" {
fmt.Fprintf(stdin, "From: %s\n", from)
}
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))
Expand All @@ -87,7 +92,11 @@ func sendEmail(ctx context.Context, to []string, notif *notification) error {
fmt.Fprintf(stdin, "\n")
fmt.Fprint(stdin, notif.text)

args := []string{"-i", "--"}
args := []string{"-i"}
if from != "" {
args = append(args, "-f", from)
}
args = append(args, "--")
args = append(args, to...)

sendmail := exec.CommandContext(ctx, sendmailPath(), args...)
Expand Down

0 comments on commit 97b9479

Please sign in to comment.