- curl_easy_setopt(curl, CURLOPT_UPLOAD, 1); // tell libcurl we are uploading
- curl_easy_setopt(curl, CURLOPT_TIMEOUT, 20L); // Time out after 20 seconds
-
- strcpy(try_this_mx, "smtp://");
- extract_token(&try_this_mx[7], mxes, i, '|', (sizeof try_this_mx - 7));
- curl_easy_setopt(curl, CURLOPT_URL, try_this_mx);
-
- syslog(LOG_DEBUG, "smtpclient: trying %s", try_this_mx); // send the message
+ curl_easy_setopt(curl, CURLOPT_UPLOAD, 1); // tell libcurl we are uploading
+ curl_easy_setopt(curl, CURLOPT_TIMEOUT, 20L); // Time out after 20 seconds
+ if (CtdlGetConfigInt("c_smtpclient_disable_starttls") == 0) {
+ curl_easy_setopt(curl, CURLOPT_USE_SSL, CURLUSESSL_TRY); // Attempt STARTTLS if offered
+ }
+ curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);
+ curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L);
+ curl_easy_setopt(curl, CURLOPT_DEBUGFUNCTION, ctdl_libcurl_smtp_debug_callback);
+ curl_easy_setopt(curl, CURLOPT_DEBUGDATA, (void *) response);
+ curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
+
+ // Construct an SMTP URL in the form of:
+ // smtp[s]://target_host/source_host
+ // This looks weird but libcurl uses that last part to set our name for EHLO or HELO.
+ // We check for "smtp://" and "smtps://" because the admin may have put those prefixes in a smart-host entry.
+ // If there is no prefix we add "smtp://"
+ extract_token(try_this_mx, mxes, i, '|', (sizeof try_this_mx - 7));
+ snprintf(smtp_url, sizeof smtp_url, "%s%s/%s", (((!strncasecmp(try_this_mx, HKEY("smtp://")))
+ ||
+ (!strncasecmp
+ (try_this_mx,
+ HKEY("smtps://")))) ? "" : "smtp://"),
+ try_this_mx, CtdlGetConfigStr("c_fqdn")
+ );
+ curl_easy_setopt(curl, CURLOPT_URL, smtp_url);
+ syslog(LOG_DEBUG, "smtpclient: trying MX %d of %d <%s>", i+1, num_mx, smtp_url); // send the message