Browse files

[enhance] Mail: following pull request from mattgu74 (MLstate#20)

Sending email via a specified Smtp Server
When the server is in intranet, it's not always possible to reach smtp server present in MX record.

Then I have add an optional argument to specify a smtp server adress you want to use for sending email.
  • Loading branch information...
1 parent 7affb20 commit c8dd8906d417e845dc302dcbb20b3f47587c8670 @Aqua-Ye Aqua-Ye committed Jan 9, 2012
Showing with 14 additions and 6 deletions.
  1. +4 −2 libnet/smtpClient.ml
  2. +3 −2 opabsl/mlbsl/bslMail.ml
  3. +7 −2 stdlib/web/mail/email.opa
View
6 libnet/smtpClient.ml
@@ -234,7 +234,7 @@ let read_code s =
let analyze_error = Mailerror.parse_mailerror_error
let mail_send_aux ?client_certificate ?verify_params ?(secure=false) sched
- ?subject mfrom mdst ?mto mdata ?return_path ?html ?files ?custom_headers ?cte ?charset nb_attempt ?(port=25) cont () =
+ ?subject mfrom mdst ?mto mdata ?return_path ?html ?files ?custom_headers ?cte ?charset nb_attempt ?(port=25) ?via cont () =
let mto =
match mto with
| Some tos -> tos
@@ -309,7 +309,9 @@ let mail_send_aux ?client_certificate ?verify_params ?(secure=false) sched
SCC.err_cont = None;
SCC.extra_params = (mail,domain_from,tools)
} in
- let dst_string = Network.string_of_ipv4 dst_ip in
+ let dst_string = match via with
+ | Some str_server -> str_server
+ | None -> Network.string_of_ipv4 dst_ip in
let secure_mode =
if secure
then Network.Secured (client_certificate, verify_params)
View
5 opabsl/mlbsl/bslMail.ml
@@ -28,9 +28,10 @@
##register [cps-bypass] mail_send_fun : string, string, string, string, string, string, string,\
caml_list(caml_tuple_4(string,string,string,string)), \
caml_list(caml_tuple_2(string,string)), \
+ option(string), \
(opa[email_send_status], continuation(opa[void]) -> void), \
continuation(opa[void]) -> void
- let mail_send_fun mfrom mfrom_address_only mdst mto subject mdata html files custom_headers cont k =
+ let mail_send_fun mfrom mfrom_address_only mdst mto subject mdata html files custom_headers via cont k =
let cont = BslUtils.proj_cps k cont in
let cont x =
let res =
@@ -54,7 +55,7 @@
in
let html = if html = "" then None else Some html
and mto = if mto = "" then None else Some mto in
- SmtpClient.mail_send_aux BslScheduler.opa ~charset:"UTF-8" ~subject mfrom mdst ?mto:mto mdata ?html:html ~files ~custom_headers ~return_path:mfrom_address_only 10 cont ();
+ SmtpClient.mail_send_aux BslScheduler.opa ~charset:"UTF-8" ~subject mfrom mdst ?mto:mto mdata ?html:html ~files ~custom_headers ~return_path:mfrom_address_only 10 ?via:via cont ();
QmlCpsServerLib.return k ServerLib.void
##endmodule
View
9 stdlib/web/mail/email.opa
@@ -96,6 +96,7 @@ type Email.options = {
cc : list(Email.email)
custom_headers : list((string, string))
files : Email.attachments
+ via : option(string)
}
type caml_tuple_2('a,'b) = external
@@ -111,6 +112,7 @@ Email = {{
cc = []
custom_headers = []
files = []
+ via = none
} : Email.options
/**
@@ -257,7 +259,7 @@ Email = {{
aux(List.rev(l),%%BslNativeLib.empty_list%%)
@private
- send_mail = %% BslMail.Mailserve.mail_send_fun %% : string , string, string , string , string , string, string, caml_list(caml_tuple_4(string,string,string,string)), caml_list(caml_tuple_2(string, string)), (Email.send_status -> void) -> void
+ send_mail = %% BslMail.Mailserve.mail_send_fun %% : string , string, string , string , string , string, string, caml_list(caml_tuple_4(string,string,string,string)), caml_list(caml_tuple_2(string, string)), option(string), (Email.send_status -> void) -> void
@private
send_async(
@@ -302,7 +304,10 @@ Email = {{
if i == 0 then to_string(e)
else acc ^ ", " ^ to_string(e)
, options.to, "")
- send_mail(to_string(from), to_string_only_address(from), to_string_only_address(to), mto, subject, text, html, files, custom_headers, k)
+ send_mail(
+ to_string(from), to_string_only_address(from), to_string_only_address(to), mto,
+ subject, text, html, files, custom_headers, options.via, k
+ )
/**
* Try to send a mail {b synchronously}

0 comments on commit c8dd890

Please sign in to comment.