let sendmail ?(bin="sendmail") mail =
try
let com = Printf.sprintf "%s -t %s"
bin (String.concat " " (List.map Filename.quote mail.mail_to))
in
let oc = Unix.open_process_out com in
let (mes_id, mes) = make_mail mail in
output_string oc mes;
match Unix.close_process_out oc with
Unix.WEXITED 0 -> mes_id
| Unix.WEXITED n ->
let msg = Printf.sprintf "Command %s exited with code %d"
com n
in
failwith msg
| Unix.WSTOPPED n ->
let msg = Printf.sprintf "Command %s stopped by signal %d"
com n
in
failwith msg
| Unix.WSIGNALED n ->
let msg = Printf.sprintf "Command %s killed by signal %d"
com n
in
failwith msg
with
Unix.Unix_error (e,s1,s2) ->
let msg = Printf.sprintf "%s: %s %s"
(Unix.error_message e) s1 s2
in
failwith msg
| e ->
let s = Printexc.to_string e in
failwith s