Reputation: 8384
My C++ code is like this
CURL *curl;
CURLcode curlres;
struct curl_slist *recipients = NULL;
char from[128] = "<[email protected]>";
char to[128] = "[email protected]";
curl = curl_easy_init();
curl_easy_setopt(curl, CURLOPT_URL, COOLCAST_MAILER_URL);
curl_easy_setopt(curl, CURLOPT_MAIL_FROM, from);
recipients = curl_slist_append(recipients, to);
curl_easy_setopt(curl, CURLOPT_MAIL_RCPT, recipients);
curl_easy_setopt(curl, CURLOPT_READFUNCTION, payload_source);
curl_easy_setopt(curl, CURLOPT_READDATA, NULL);
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);
curlres = curl_easy_perform(curl);
if(curlres != CURLE_OK)
qDebug() << "Encountered error in sending email";
The output on the screen looks like this:
[ec2-user@ip-10-0-0-51 mailman]$ /path/to/executable
* Rebuilt URL to: smtp://localhost/
* Hostname was NOT found in DNS cache
* Trying 127.0.0.1...
* Connected to localhost (127.0.0.1) port 25 (#0)
< 220 ip-10-0-0-51 ESMTP Sendmail 8.14.4/8.14.4; Sat, 3 May 2014 19:35:57 GMT
> EHLO ip-10-0-0-51
< 250-ip-10-0-0-51 Hello localhost [127.0.0.1], pleased to meet you
< 250-ENHANCEDSTATUSCODES
< 250-PIPELINING
< 250-8BITMIME
< 250-SIZE
< 250-DSN
< 250-ETRN
< 250-DELIVERBY
< 250 HELP
> VRFY [email protected]
< 252 2.5.2 Cannot VRFY user; try RCPT to attempt delivery (or try finger)
252 2.5.2 Cannot VRFY user; try RCPT to attempt delivery (or try finger)
* Connection #0 to host localhost left intact
Now, my smtp server is working fine. Below is a telnet session where I manually executed the following SMTP commands EHLO, MAIL FROM, RCPT TO, DATA, QUIT and the email got delivered successfully
[ec2-user@ip-10-0-0-51 mailman]$ telnet localhost 25
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
220 ip-10-0-0-51 ESMTP Sendmail 8.14.4/8.14.4; Sat, 3 May 2014 19:36:41 GMT
MAIL FROM: [email protected]
250 2.1.0 [email protected]... Sender ok
RCPT TO: [email protected]
250 2.1.5 [email protected]... Recipient ok
DATA
354 Enter mail, end with "." on a line by itself
This is a test mail
.
250 2.0.0 s43Jaf12000302 Message accepted for delivery
QUIT
221 2.0.0 ip-10-0-0-51 closing connection
Connection closed by foreign host.
It seems the real issue in my libcurl
usage is - it tries to issue VRFY, whereas I want it to rather use RCPT TO - which is what I did in the telnet session. Is there a way to set that option in libcurl
? Or is there some other problem with the code?
Upvotes: 0
Views: 2665
Reputation: 31
Try adding
curl_easy_setopt(curl, CURLOPT_UPLOAD, 1L);
See http://curl.haxx.se/libcurl/c/smtp-mail.html
Upvotes: 3