libcurl 发送邮件_使用libcurl的SMTP邮件

I compiled the c example the ships with libcurl.

The source file is smtp-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 this

int 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 be smtp://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?

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值