email.scm 653 B

1234567891011121314151617181920212223242526
  1. (define-module (email)
  2. #:use-module (ice-9 popen)
  3. #:use-module (ice-9 threads)
  4. #:use-module (srfi srfi-19)
  5. #:export (send-email))
  6. (define (send-email to subject body)
  7. (call-with-new-thread
  8. (lambda ()
  9. (let ((port (open-pipe* OPEN_WRITE "msmtp" to)))
  10. (display (email-rfc-2822 subject body) port)
  11. (close-pipe port)))))
  12. (define (email-rfc-2822 subject body)
  13. (string-append
  14. "Subject: " subject "\n"
  15. "Date: "
  16. (date->string (current-date) "~a, ~e ~b ~Y ~k:~M:~S ~z")
  17. "\n"
  18. "Message-ID: <"
  19. (number->string (hash (string-append subject body) 1000000000000000000))
  20. "@"
  21. (gethostname)
  22. ">\n\n"
  23. body))