sendmail ~hostname ?port ~domain ~authenticator ?authentication sender recipients mail where:
hostname is the hostname of the peerport the port of the SMTP peerdomain is the domain of the sender (probably localhost)authenticator is the TLS authenticatorauthentication is the username and the password of the usersender is the senderrecipients are recipients of the emailmail stream of the mail
The connection already start a TLS connection to the peer. The peer is probably available on *:465 (the default of port argument). The mail stream must emit for each chunk a CRLF at the end (a line). As an user of GMail, the call of sendmail looks like:
open Mrmime
let my_domain = Colombe.Domain.of_string_exn (Unix.gethostname ())
let my_authentication =
{ Sendmail.username= "my_login"
; Sendmail.password= "my_password"
; Sendmail.mechanism= Sendmail.PLAIN }
let sender =
let open Mrmime.Mailbox in
let v = Local.[ "my"; "address"; "mail" ] @ Domain.(domain, [ "gmail"; "com" ]) in
Result.get_ok (Colombe_emile.to_reverse_path v)
(* "my.address.mail@gmail.com" *)
let destination =
let open Mrmime.Mailbox in
let v = Local.[ "to"; "joe" ] @ Domain.(domain, [ "gmail"; "com" ]) in
Result.get_ok (Colombe_emile.to_forward_path v)
(* "to.joe@gmail.com" *)
let run () = sendmail
~hostname:Domain_name.(host_exe (of_string_exn "gmail.com"))
~domain:my_domain
~authentictor
~authentication
sender [ destination ]
mail
let () = match Lwt_main.run (run ()) with
| Ok () -> ()
| Error err -> Format.eprintf "%a.\n%!" Sendmail.pp_error err
sendmail does not strictly depend on mrmime or emile. However, we advise to use them to produce typed and well-formed mails. sendmail does not handle properly contents of mails as are. It just emits the stream to the pipeline directly without any changes if the line does not start with a dot ("."). Otherwise, it prepends the line with a new dot (which has a signification in terms of SMTP).
We assume that each call of mail () gives to us a line - something which ends up with CRLF ("\r\n"). By this way, we can sanitize the dot character - and only on this way.
mrmime ensures to make on its way a stream which emits line per line. A non-user of mrmime should be aware about this assumption.
sendmail starts by itself a TLS connection with the SMTP server.