2014-05-03 51 views
0

我的C++代碼是這樣的無法使用的libcurl

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"; 

屏幕上的輸出,以發送電子郵件看起來是這樣的:

[[email protected] 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 

現在,我的SMTP服務器工作正常。下面是我手動執行以下SMTP命令EHLO,MAIL FROM,RCPT TO,DATA telnet會話,QUIT和電子郵件得到了成功交付

[[email protected] 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. 

看來我libcurl使用真正的問題是 - 它會嘗試發佈VRFY,而我希望它使用RCPT TO - 這正是我在telnet會話中所做的。有沒有辦法在libcurl中設置該選項?還是有代碼的其他問題?

回答