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