使用libcurl的SMTP邮件 [英] SMTP mail using libcurl
问题描述
我编译的C例子中附带的libcurl。结果
源文件是 SMTP-tls.c
结果
试图用它通过Gmail来发送邮件,这是我得到结果的响应
- 关于以()连接到smtp.gmail.com端口465(#0)
- 试图74.125.115.109 ... *连接
使用基本与用户的xxxxxxx@gmail.com服务器授权
GET / HTTP / 1.1授权:基本xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx主持人:smtp.gmail.com:465
接受: / 的
块引用>
从服务器空回复
- 连接#0主办smtp.gmail.com原封不动
- 服务器返回什么(无头,无数据)
- 关闭连接#0
结果
块引用>我错过了什么?我没有修改code,除了在可变投入任何方式。在这个机器上我能够发送和接收使用电子邮件Outlook 2003的结果
编辑结果
尝试了不同的端口。这是结果结果
- 关于以()连接到smtp.gmail.com端口587(#0)
- 试图74.125.93.109 ... *连接
- 使用基本与用户的服务器认证xxxxxxx@gmail.com
GET / HTTP / 1.1授权:基本xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx主持人:smtp.gmail.com:587
接受: / 的
220 mx.google.com ESMTP ew54y2x5of95qdz.12 502 5.5.1无法识别
命令。 ew54y2x5of95qdz.12
*连接#0主办smtp.gmail.com保持不变
*关闭连接#0结果
块引用>
块引用>修改结果
主要是这样的结果。INT的main()
{
卷曲*卷曲;
卷曲code资源;
结构curl_slist *收件人= NULL;
结构upload_status upload_ctx; upload_ctx.lines_read = 0; 卷曲= curl_easy_init();
如果(卷曲){
curl_easy_setopt(卷曲,CURLOPT_URL,SMTP://gmail.com:587);
curl_easy_setopt(卷曲,CURLOPT_USE_SSL,CURLUSESSL_ALL);
curl_easy_setopt(卷曲,CURLOPT_USERNAME,xxxxxx@gmail.com);
curl_easy_setopt(卷曲,CURLOPT_PASSWORD,XXXXXXXX);
curl_easy_setopt(卷曲,CURLOPT_MAIL_FROM,FROM);
收件人= curl_slist_append(受助人);
收件人= curl_slist_append(收件人,CC);
curl_easy_setopt(卷曲,CURLOPT_MAIL_RCPT,收件人);
curl_easy_setopt(卷曲,CURLOPT_READFUNCTION,payload_source);
curl_easy_setopt(卷曲,CURLOPT_READDATA,&安培; upload_ctx);
curl_easy_setopt(卷曲,CURLOPT_VERBOSE,1);
RES = curl_easy_perform(卷曲);
curl_slist_free_all(收件人);
curl_easy_cleanup(卷曲);
}
返回0;
}结果编辑结果
貌似正确的网址应该是SMTP://smtp.gmail.com:587
结果
这让我进一步,现在我得到结果。*关于为()连接到smtp.gmail.com端口587(#0)
*尝试74.125.45.108 ... *连接
< 220 mx.google.com ESMTP j26srtuiopnann.7
> EHLO my_computer_name
< 250-mx.google.com为您服务,
< 250-SIZE 35882577
< 250-8BITMIME
< 250-STARTTLS
< 250 ENHANCEDSTATUS codeS
*无已知的验证机制的支持!
>放弃
< 221 2.0.0收盘连接j26srtuiopnann.7
*关闭连接#0
*拒绝登录结果编辑结果
的libcurl不支持SSL的内置解决方案第一输出有看起来像你喂libcurl的一个HTTP URL。
使用您的编辑问题,现在的问题变成完全不同的东西。现在,而不是看起来像你也许不具备在建的libcurl启用了SSL?
I compiled the c example the ships with libcurl.
The source file issmtp-tls.c
Tried to use it to send mail through gmail and this is the response that I got
- About to connect() to smtp.gmail.com port 465 (#0)
- Trying 74.125.115.109... * connected
Server auth using Basic with user 'xxxxxxx@gmail.com'
GET / HTTP/1.1 Authorization: Basic xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx Host: smtp.gmail.com:465 Accept: /
Empty reply from server
- Connection #0 to host smtp.gmail.com left intact
- Server returned nothing (no headers, no data)
- Closing connection #0
What did I miss? I did not modify the code in any way except for the variable inputs. On this machine I am able to send and receive mail using Outlook 2003.
EDIT
Tried a different port. This is the result
- About to connect() to smtp.gmail.com port 587 (#0)
- Trying 74.125.93.109... * connected
- Server auth using Basic with user 'xxxxxxx@gmail.com'
GET / HTTP/1.1 Authorization: Basic xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx Host: smtp.gmail.com:587 Accept: /
220 mx.google.com ESMTP ew54y2x5of95qdz.12 502 5.5.1 Unrecognized command. ew54y2x5of95qdz.12 * Connection #0 to host smtp.gmail.com left intact * Closing connection #0
EDIT
Main looks like thisint main() { CURL *curl; CURLcode res; struct curl_slist *recipients = NULL; struct upload_status upload_ctx; upload_ctx.lines_read = 0; curl = curl_easy_init(); if (curl) { curl_easy_setopt(curl, CURLOPT_URL, "smtp://gmail.com:587"); curl_easy_setopt(curl, CURLOPT_USE_SSL, CURLUSESSL_ALL); curl_easy_setopt(curl, CURLOPT_USERNAME, "xxxxxx@gmail.com"); curl_easy_setopt(curl, CURLOPT_PASSWORD, "xxxxxxxx"); curl_easy_setopt(curl, CURLOPT_MAIL_FROM, FROM); recipients = curl_slist_append(recipients, TO); recipients = curl_slist_append(recipients, CC); curl_easy_setopt(curl, CURLOPT_MAIL_RCPT, recipients); curl_easy_setopt(curl, CURLOPT_READFUNCTION, payload_source); curl_easy_setopt(curl, CURLOPT_READDATA, &upload_ctx); curl_easy_setopt(curl, CURLOPT_VERBOSE, 1); res = curl_easy_perform(curl); curl_slist_free_all(recipients); curl_easy_cleanup(curl); } return 0; }
EDIT
Looks like the correct URL should besmtp://smtp.gmail.com:587
This gets me further, now I am getting* About to connect() to smtp.gmail.com port 587 (#0) * Trying 74.125.45.108... * connected < 220 mx.google.com ESMTP j26srtuiopnann.7 > EHLO my_computer_name < 250-mx.google.com at your service, < 250-SIZE 35882577 < 250-8BITMIME < 250-STARTTLS < 250 ENHANCEDSTATUSCODES * No known auth mechanisms supported! > QUIT < 221 2.0.0 closing connection j26srtuiopnann.7 * Closing connection #0 * Login denied
EDIT
Libcurl was not built with SSL support解决方案The first output there looks like you're feeding libcurl a HTTP URL.
With your edited question the problem now turned into something completely different. Now it rather looks like you perhaps don't have SSL enabled in your built libcurl?
这篇关于使用libcurl的SMTP邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!