2 * Written by Richard W.M. Jones <rich@merjis.com>.
3 * Copyright (C) 2004 Merjis Ltd.
4 * $Id: cocanwiki_emailnotify.ml,v 1.2 2004/09/07 14:58:34 rich Exp $
12 (* This is where we coordinate email notification from various
13 * scripts which create or update the wiki.
15 let email_notify ~subject ~body (dbh : Dbi.connection) hostid =
16 (* Is anyone listed for email notification at this host? *)
17 let sth = dbh#prepare_cached "select email, name from email_notify
19 sth#execute [`Int hostid];
21 let to_addr = sth#map (function
22 | [`String email; `String name] ->
23 name ^ " <" ^ email ^ ">"
24 | [`String email; `Null] ->
26 | _ -> assert false) in
28 if to_addr <> [] then (
29 (* Prepare the body of the message. The assumption is that
30 * this takes time and database access, so we defer the creation
31 * of the body until we know that someone needs to be notified.
35 let subject = "Wiki notice: " ^ subject in
38 Sendmail.send_mail ~subject ~to_addr ~body ()