Respect $EMAIL when sending emails
Envelope sender and RFC5322.From address are set to $EMAIL if it's non-empty. Requested in #87
This commit is contained in:
parent
b5f9a48dc3
commit
cd4d796a7c
|
@ -215,6 +215,11 @@ and non-zero when a serious error occurs.
|
||||||
: Directory from which any configuration, such as the watch list, is read.
|
: Directory from which any configuration, such as the watch list, is read.
|
||||||
Defaults to `~/.certspotter`.
|
Defaults to `~/.certspotter`.
|
||||||
|
|
||||||
|
`EMAIL`
|
||||||
|
|
||||||
|
: Email address from which to send emails. If not set, certspotter lets sendmail pick
|
||||||
|
the address.
|
||||||
|
|
||||||
`HTTPS_PROXY`
|
`HTTPS_PROXY`
|
||||||
|
|
||||||
: URL of proxy server for making HTTPS requests. `http://`, `https://`, and
|
: URL of proxy server for making HTTPS requests. `http://`, `https://`, and
|
||||||
|
|
|
@ -67,6 +67,11 @@ func sendEmail(ctx context.Context, to []string, notif *notification) error {
|
||||||
stdin := new(bytes.Buffer)
|
stdin := new(bytes.Buffer)
|
||||||
stderr := 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, "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, "Date: %s\n", time.Now().Format(mailDateFormat))
|
||||||
|
@ -77,7 +82,11 @@ func sendEmail(ctx context.Context, to []string, notif *notification) error {
|
||||||
fmt.Fprintf(stdin, "\n")
|
fmt.Fprintf(stdin, "\n")
|
||||||
fmt.Fprint(stdin, notif.text)
|
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...)
|
args = append(args, to...)
|
||||||
|
|
||||||
sendmail := exec.CommandContext(ctx, sendmailPath(), args...)
|
sendmail := exec.CommandContext(ctx, sendmailPath(), args...)
|
||||||
|
|
Loading…
Reference in New Issue