I'm trying to write a simple C++ code that sends an email to another address with libcurl.
I wrote this, which compiles correctly, but I run it and get the message:
Error: Problem with the local SSL certificate (58)
#include <iostream>
#include <curl/curl.h>
int main() {
// Creating the message
std::string from = "[email protected]";
std::string to = "[email protected]";
std::string password = "password";
std::string subject = "Object";
std::string body = "This is may message\n";
// Configuring cURL
CURL *curl;
CURLcode res = CURLE_OK;
curl_global_init(CURL_GLOBAL_DEFAULT);
curl = curl_easy_init();
if(curl) {
// Configuration of the recipient, sender, subject and body of the message
struct curl_slist *recipients = NULL;
recipients = curl_slist_append(recipients, ("To: " + to).c_str());
recipients = curl_slist_append(recipients, ("From: " + from).c_str());
recipients = curl_slist_append(recipients, ("Subject: " + subject).c_str());
// Configuring cURL options
curl_easy_setopt(curl, CURLOPT_URL, "smtps://authsmtp.securemail.pro:465");
curl_easy_setopt(curl, CURLOPT_USE_SSL, CURLUSESSL_ALL);
curl_easy_setopt(curl, CURLOPT_MAIL_FROM, from.c_str());
curl_easy_setopt(curl, CURLOPT_MAIL_RCPT, recipients);
curl_easy_setopt(curl, CURLOPT_USERNAME, from.c_str());
curl_easy_setopt(curl, CURLOPT_PASSWORD, password.c_str());
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYSTATUS, 1L);
curl_easy_setopt(curl, CURLOPT_CAPATH, "/etc/ssl/certs");
curl_easy_setopt(curl, CURLOPT_SSLCERT, "/etc/ssl/certs/ca-certificates.crt");
// Sending the message body
curl_easy_setopt(curl, CURLOPT_READFUNCTION, NULL);
curl_easy_setopt(curl, CURLOPT_UPLOAD, 1L);
curl_easy_setopt(curl, CURLOPT_READDATA, body.c_str());
// Executing the request
res = curl_easy_perform(curl);
// Cleaning and closing
curl_slist_free_all(recipients);
curl_easy_cleanup(curl);
}
// Error handling
if(res != CURLE_OK)
std::cerr << "Error: " << curl_easy_strerror(res) << " (" << res << ")"<< std::endl;
curl_global_cleanup();
return 0;
I attempted to send with curl with the following command:
curl smtps://authsmtp.securemail.pro:465 -v --mail-from "[email protected]" --mail-rcpt "[email protected]" --ssl -u [email protected]:password -T "test.txt" -k --anyauth
EXTRACT OF THE RESULT
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0* Trying 81.88.48.66:465...
* Connected to authsmtp.securemail.pro (81.88.48.66) port 465 (#0)
* successfully set certificate verify locations:
* CAfile: /etc/ssl/certs/ca-certificates.crt
* CApath: /etc/ssl/certs
* Server certificate:
* subject: C=IT; ST=Firenze; O=Register S.p.A.; CN=*.securemail.pro
* start date: Feb 17 00:00:00 2023 GMT
* expire date: Mar 3 23:59:59 2024 GMT
* issuer: C=GB; ST=Greater Manchester; L=Salford; O=Sectigo Limited; CN=Sectigo RSA Organization Validation Secure Server CA
* SSL certificate verify ok.
< 235 2.7.0 ... authentication succeeded
} [5 bytes data]
> MAIL FROM:<[email protected]> SIZE=13
{ [5 bytes data]
< 250 2.1.0 <[email protected]> sender ok
} [5 bytes data]
> RCPT TO:<[email protected]>
{ [5 bytes data]
< 250 2.1.5 <[email protected]> recipient ok
} [5 bytes data]
> DATA
{ [5 bytes data]
< 354 OK
} [5 bytes data]
* We are completely uploaded and fine
} [5 bytes data]
< 250 2.0.0 WF8GrZuZ7JFspWF8HrHGcu mail accepted for delivery
100 13 0 0 100 13 0 37 --:--:-- --:--:-- --:--:-- 37
* Connection #0 to host authsmtp.securemail.pro left intact
On [email protected] I receive mailer-daemon. In my opinion it is a permissions problem but they are the system ones that normally work with Thunderbird I'm trying with Debian 11 and libcurl 7.74, but I also tried in Windows 10 with libcurl 8 and the result is the same