[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: guile - sending emails
From: |
Chris Vine |
Subject: |
Re: guile - sending emails |
Date: |
Mon, 20 Oct 2014 22:13:56 +0100 |
On Mon, 20 Oct 2014 22:17:47 +0200
Konrad Makowski <address@hidden> wrote:
> How can i send emails from guile script? Is there any module for that
> purpose? I know that there is mailutils but can't figure out how to
> do that with it. Please, show me some examples.
I use mailx for that together with guile-lib's (os process) module,
mainly because I know what they do, I have used them before and they
work. Here is part of a daemon script I use to broadcast a change of
ip address to a list of recipients for internal purposes. It should
be self-explanatory: there are various things defined elsewhere in the
script.
(define (send-ip ip changed)
(let ([preamble (if changed "Changed: " "Reminder: ")])
(log (string-append preamble "sending " ip " to "
(reduce (lambda (cur prev)
(string-append prev " " cur))
""
to-mail-addr)))
(let* ([res (apply run-with-pipe "w" "mailx" "-s" "IP" "-r" from-mail-addr
to-mail-addr)]
[pid (car res)]
[output (cdr res)])
(put-string output (string-append preamble ip "\n"))
(close-port output) ;; closing the pipe causes mailx to unblock and send
(let ([ret (status:exit-val (cdr (waitpid pid)))])
(when (or (not ret)
(not (= ret 0)))
(log "Error invoking mailx"))))))