这是我的libcurl代码。我正在尝试在linux中向我自己的电子邮件域发送电子邮件。
这是我的样例libcurl代码。
curl_easy_setopt(curl, CURLOPT_USERNAME, "username@mydomain.com");
curl_easy_setopt(curl, CURLOPT_PASSWORD, "mypassword");
curl_easy_setopt(curl, CURLOPT_URL, "smtp://mail.mydomain.com:25");
curl_easy_setopt(curl, CURLOPT_USE_SSL, (long)CURLUSESSL_ALL);
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_INFILESIZE, file_size);
curl_easy_setopt(curl, CURLOPT_READFUNCTION, fileBuf_source);
curl_easy_setopt(curl, CURLOPT_READDATA, &file_upload_ctx);
curl_easy_setopt(curl, CURLOPT_UPLOAD, 1L);
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L); //Dont display Curl Connection data Change 1L to 0
res = curl_easy_perform(curl);当我运行这段代码时,我得到了下面的错误。
* Rebuilt URL to: smtp://mail.mydomain.com:25/
* Hostname was NOT found in DNS cache
* Trying <My mail domain Ip address>...
* Connected to mail.mydomain.com (<My mail domain Ip address>) port 25 (#0)
< 220 mail.mydomain.com ESMTP
> EHLO client6
< 250-mail.mydomain.com
< 250-PIPELINING
< 250-SIZE 20480000
< 250-VRFY
< 250-ETRN
< 250-STARTTLS
< 250-AUTH PLAIN LOGIN
< 250-ENHANCEDSTATUSCODES
< 250-8BITMIME
< 250 DSN
> STARTTLS
< 220 2.0.0 Ready to start TLS
* successfully set certificate verify locations:
* CAfile: none
CApath: /etc/ssl/certs
* SSL certificate problem: self signed certificate
* Closing connection 0
curl_easy_perform() failed: Peer certificate cannot be authenticated with given CA certificates发布于 2016-06-19 03:41:33
您的问题是您的服务器提供了一个自签名证书,因此curl无法验证它的出处。您有几个选项:
CURLOPT_SSL_VERIFYPEER设置为0来禁用验证。然而,这是非常不鼓励的,因为它使访问不安全。您只应出于测试目的,或在极少数情况下保证客户端和服务器之间的网络是安全的情况下才执行此操作。https://stackoverflow.com/questions/37814590
复制相似问题