X-Git-Url: https://code.citadel.org/?a=blobdiff_plain;f=citadel%2Fmodules%2Fsmtp%2Fserv_smtpclient.c;h=372dddbc49e8abdcbde463560a18c7dada792538;hb=3f6d0a56adb237cd673176e75605ea2e038b0860;hp=6889b02f5f348ec1e9445641f763491bf17ac235;hpb=e296d020094c0c326fd00c1a3f420f2f6aafd019;p=citadel.git diff --git a/citadel/modules/smtp/serv_smtpclient.c b/citadel/modules/smtp/serv_smtpclient.c index 6889b02f5..372dddbc4 100644 --- a/citadel/modules/smtp/serv_smtpclient.c +++ b/citadel/modules/smtp/serv_smtpclient.c @@ -198,6 +198,7 @@ int smtp_attempt_delivery(long msgid, char *recp, char *envelope_from) char node[1024]; char name[1024]; char try_this_mx[256]; + char smtp_url[512]; int i; syslog(LOG_DEBUG, "smtpclient: smtp_attempt_delivery(%ld, %s)", msgid, recp); @@ -236,22 +237,25 @@ int smtp_attempt_delivery(long msgid, char *recp, char *envelope_from) curl_easy_setopt(curl, CURLOPT_READDATA, &s); curl_easy_setopt(curl, CURLOPT_UPLOAD, 1); // tell libcurl we are uploading curl_easy_setopt(curl, CURLOPT_TIMEOUT, 20L); // Time out after 20 seconds + // curl_easy_setopt(curl, CURLOPT_USE_SSL, CURLUSESSL_TRY); athos-mn curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L); curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L); // curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, curl_error_buffer); - strcpy(try_this_mx, "smtp://"); - extract_token(&try_this_mx[7], mxes, i, '|', (sizeof try_this_mx - 7)); - if ( - (!strncasecmp(try_this_mx, HKEY("smtp://smtp://"))) // This can happen if the administrator - || (!strncasecmp(try_this_mx, HKEY("smtp://smtps://"))) // puts a full smtp[s] URI as the smart-host - ) { - strcpy(try_this_mx, &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 + // 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 %s", smtp_url); // send the message res = curl_easy_perform(curl); curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &response_code); syslog(LOG_DEBUG, "smtpclient: libcurl returned %d (%s) , SMTP response %ld",