gpt4 book ai didi

c - 使用 libcurl 的 SMTP 邮件

转载 作者:行者123 更新时间:2023-12-04 06:10:48 25 4
gpt4 key购买 nike

我用 libcurl 编译了 c 示例。
源文件是smtp-tls.c
尝试使用它通过 gmail 发送邮件,这是我得到的回复

  • 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: /

  • 来自服务器的空回复

  • 与主机 smtp.gmail.com 的连接 #0 保持完好
  • 服务器没有返回任何内容(没有标题,没有数据)
  • 关闭连接#0

我错过了什么?除了变量输入,我没有以任何方式修改代码。在这台机器上,我可以使用 Outlook 2003 发送和接收邮件。
编辑
尝试了不同的端口。这是结果

  • 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 无法识别 命令。 ew54y2x5of95qdz.12 * 到主机 smtp.gmail.com 的连接 #0 完好无损 * 关闭连接#0

编辑
主要看起来像这样

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


编辑
看起来正确的 URL 应该是 smtp://smtp.gmail.com:587
这让我更进一步,现在我得到了

* 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


编辑
Libcurl 不是使用 SSL 支持构建的

最佳答案

那里的第一个输出看起来像是您正在向 libcurl 提供 HTTP URL。

随着您编辑的问题,问题现在变成了完全不同的东西。现在看起来您可能没有在构建的 libcurl 中启用 SSL?

关于c - 使用 libcurl 的 SMTP 邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7809693/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com