0
votes

We have an application which sends notification email through exchange server. Right now if exchange is configured for SSL or TLS encryption, we are able to send the mail. If exchange is not configured for any encryption, the application is failing to send mail. The question is

  1. Does Libcurl support sending email without encryption?

We were using Wireshark and found that it using StartTLS for sending the mail. Below is the code snippet we are using to send mail:

curl_easy_setopt(curl, CURLOPT_URL, "smtp.url.com:25");
curl_easy_setopt(curl, CURLOPT_LOGIN_OPTIONS, "AUTH=NTML PLAIN");
curl_easy_setopt(curl, CURLOPT_USERPWD, "user:password");
curl_easy_setopt(curl, CURLOPT_MAIL_FROM, FROM_ADDR);
recipients = curl_slist_append(recipients, TO_ADDR);
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_UPLOAD, 1L);
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
res = curl_easy_perform(curl);

Please let me know what are we missing here.

1
Look at the CURLOPT_USE_SSL option. What version of libcurl are you using, though? libcurl honors an SMTP server's STARTTLS capability and has done so since early 2013. Prior to that, libcurl would send STARTTLS whether the server supported it or not. STARTTLS on SMTP is not generally used on port 25, usually on port 587 instead. - Remy Lebeau
we are using libcurl version 7.57.0. As per support.google.com/a/answer/176600?hl=en , if i want to send mail without encryption (using aspmx.l.google.com server), I have to use port 25 which I posted in example. "SMTP is not generally used on port 25": Does it mean that I need to use port 587 instead of 25 when it is trying for StartTLS ? - DTdev
if you use port 587 then you are pretty much guaranteed that STARTTLS will be used, unless you disable SSL via CURLOPT_USE_SSL or recompiling libcurl without SSL support. If libcurl is sending STARTTLS when CURLOPT_USE_SSL is set to CURLUSESSL_NONE, I would consider that a bug that should be reported. - Remy Lebeau

1 Answers

0
votes

if we add CURLOPT_USE_SSL with CURLUSESSL_NONE as shown below, it works.

if(<condition to mark that mail is using no encryption>)
curl_easy_setopt(curl, CURLOPT_USE_SSL, CURLUSESSL_NONE);