cURL / Mailing Lists / curl-library / Single Mail

curl-library

SMTP - Multiple Email Addresses

From: Tom Sparrow <tom.sparrow25_at_gmail.com>
Date: Tue, 25 Mar 2014 18:24:20 +0900

Dear Members,

Please have a look on the SMTP related issue associated with mutiple
email addresses , where atleast one of the email address is invalid.

=============================================================================================
Scenario:
While sending email to mutiple email addresses.
called following line for every "To" email address
->emailrecipients = curl_slist_append(emailrecipients, emailaddress);
finally set this option
->curl_easy_setopt(curl, CURLOPT_MAIL_RCPT, emailrecipients);
=============================================================================================
Problem:

- In case of any invalid "emailaddress" the curl operation fails.
Single "RCPT TO:" failure stops complete email communication.

It seems to be related with http://sourceforge.net/p/curl/bugs/1116/.
=============================================================================================
Possible solutions:

1. Do email address validation before calling
curl_slist_append(recipients, emailaddress)(even this cannot always
guarantee RCPT OK)

2. Keeping track of any RCPT OK responses. If there is atleast one
RCPT OK, call "DATA" command.

The following patch is associated with solution -2. I am new to
libcurl so I have serious doubts over these changes.

Please review and give your inputs. Please suggest some better alternatives.

--- /old/lib/smtp.c 2014-03-23 20:04:15.000000000 +0900
+++ /new/lib/smtp.c 2014-03-25 17:33:16.280805152 +0900
@@ -1320,27 +1320,34 @@
   CURLcode result = CURLE_OK;
   struct SessionHandle *data = conn->data;
   struct SMTP *smtp = data->req.protop;
-
+ static int countValidRCPT=0;
   (void)instate; /* no use for this yet */
-
   if(smtpcode/100 != 2) {
- failf(data, "RCPT failed: %d", smtpcode);
- result = CURLE_SEND_ERROR;
+ if(smtp->rcpt->next || countValidRCPT) {
+ infof(data, "RCPT failed..Continue\n");
+ }
+ else {
+ failf(data, "RCPT failed: %d", smtpcode);
+ return CURLE_SEND_ERROR;
+ }
   }
   else {
+ countValidRCPT++;
+ }
     smtp->rcpt = smtp->rcpt->next;
-
     if(smtp->rcpt)
       /* Send the next RCPT TO command */
       result = smtp_perform_rcpt_to(conn);
     else {
       /* Send the DATA command */
- result = Curl_pp_sendf(&conn->proto.smtpc.pp, "%s", "DATA");
-
+ if(countValidRCPT)
+ result = Curl_pp_sendf(&conn->proto.smtpc.pp, "%s", "DATA");
+ else
+ result = CURLE_SEND_ERROR;
+ countValidRCPT=0;
       if(!result)
         state(conn, SMTP_DATA);
     }
- }

   return result;
 }
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2014-03-25