34 lines
1.6 KiB
Racket
34 lines
1.6 KiB
Racket
#lang racket/base
|
|
|
|
(require smtp
|
|
"config.rkt"
|
|
"report.rkt")
|
|
|
|
(provide maybe-send-report-mail)
|
|
|
|
(define (maybe-send-report-mail config summary errors)
|
|
(define has-errors? (positive? (summary-ref summary 'errors 0)))
|
|
(define should-send?
|
|
(and (manager-config-mail-enabled? config)
|
|
(not (null? (manager-config-mail-to config)))
|
|
(or (and has-errors? (manager-config-mail-send-on-error? config))
|
|
(and (not has-errors?) (manager-config-mail-send-on-success? config)))))
|
|
(when should-send?
|
|
(define subject (format "~a FLAC 48 kHz manager: ~a error(s), ~a converted"
|
|
(manager-config-mail-subject-prefix config)
|
|
(summary-ref summary 'errors 0)
|
|
(summary-ref summary 'converted 0)))
|
|
(define body (html-report subject summary errors))
|
|
(define mail (make-mail subject body
|
|
#:from (manager-config-mail-from config)
|
|
#:to (manager-config-mail-to config)
|
|
#:cc (manager-config-mail-cc config)
|
|
#:bcc (manager-config-mail-bcc config)
|
|
#:body-content-type "text/html"))
|
|
(send-smtp-mail mail
|
|
#:host (manager-config-mail-host config)
|
|
#:port (manager-config-mail-port config)
|
|
#:tls-encode (manager-config-mail-tls? config)
|
|
#:username (manager-config-mail-username config)
|
|
#:password (manager-config-mail-password config))))
|