Commit 6741024f9a80ba551c8be11d2746cc4945ec951c

Authored by Cédric RICARD
1 parent 90524aaa

Added send_mail() wrapper

Showing 1 changed file with 40 additions and 9 deletions   Show diff stats
calexium_lib/mail/send_mail.anubis
@@ -12,6 +12,7 @@ read tools/connections.anubis @@ -12,6 +12,7 @@ read tools/connections.anubis
12 read tools/findstring.anubis 12 read tools/findstring.anubis
13 read tools/printable_tree.anubis 13 read tools/printable_tree.anubis
14 read data_base/sqlite.anubis 14 read data_base/sqlite.anubis
  15 +read network/dns.anubis
15 read network/tools.anubis 16 read network/tools.anubis
16 read system/files.anubis 17 read system/files.anubis
17 read system/string.anubis 18 read system/string.anubis
@@ -33,15 +34,6 @@ public type SendMailResult: @@ -33,15 +34,6 @@ public type SendMailResult:
33 ok, 34 ok,
34 error, 35 error,
35 reply(Int code, String enhanced_status, List(String) lines). 36 reply(Int code, String enhanced_status, List(String) lines).
36 -  
37 -public type Send_Status:  
38 - ready, //ready to send  
39 - finished, //the mail is delivered correctly  
40 - timeout, //the mail was not sent in enough time, this is a permanent error  
41 - general_error,  
42 - error(Int code, String enhanced_status, String text), //this is SMTP permanent error 5xx, we can't deliver the mail  
43 - warning(Int code, String enhanced_status, String text), //this is SMTP temporary error 4xx, we can retry with same mail later  
44 - in_progress. //We are in sending process, it's like a lock  
45 37
46 public type Str_HostName: 38 public type Str_HostName:
47 str_host_name(String str). 39 str_host_name(String str).
@@ -535,3 +527,42 @@ public define SendMailResult @@ -535,3 +527,42 @@ public define SendMailResult
535 //before anything, then we try to extract the enhanced status if exists for relaying the mail with the ISP 527 //before anything, then we try to extract the enhanced status if exists for relaying the mail with the ISP
536 reply_handling(code,lines,true) 528 reply_handling(code,lines,true)
537 }. 529 }.
  530 +
  531 +public define SendMailResult
  532 + send_mail
  533 + (
  534 + RWStream conn,
  535 + Send_Param param,
  536 + ) =
  537 + send_mail(conn, param, (Send_Mail_Session sm_session, Send_Param param) |-> ok(param)).
  538 +
  539 +public define SendMailResult
  540 + send_mail
  541 + (
  542 + String server,
  543 + Word32 port,
  544 + Send_Param param,
  545 + )=
  546 + if resolve_address(server) is
  547 + {
  548 + failure then
  549 + logWarning(send_mail_log,"IP address NOT found for Mail server ["+server+"]");
  550 + error,
  551 +
  552 + success(ip_addr) then
  553 + with ip_txt = ip_addr_to_string(ip_addr),
  554 + logTrace(send_mail_log, send_mail_mask, "send_mail: Trying to connect to "+ip_txt);
  555 +
  556 + if (Result(NetworkConnectError,RWStream))connect(ip_addr, port) is
  557 + {
  558 + error(e) then
  559 + logTrace(send_mail_log,send_mail_mask,"send_mail: Can't connect to "+ip_txt);
  560 + error,
  561 +
  562 + ok(server_conn) then
  563 + //
  564 + //with status = to_Send_Status(send_mail(db, server_conn, send_param(str_sender(sender), str_recipient(recipient), [make_data_io(source)],auth, str_UID(file_uid) ))),
  565 + send_mail(server_conn, param),
  566 + }
  567 + }.
  568 +