Можете отправить динамической теле письма на скручиваемость
Я новичок в CURL и пытаюсь отправить динамическое тело сообщения. Но я получаю только пустую тему и тело сообщения, когда пытаюсь использовать curl lib в visual c++.
Пожалуйста помочь.
Что я уже пробовал:
<pre> size_t Process::processmail(void *ptr, size_t size, size_t nmemb, void *userp) { std::string a, b, c, d; std::string arr[MAXSPACE]; std::string search = ","; int spacePos; int currPos = 0; int k = 0; int prevPos = 0; std::string &statistics = *(static_cast<std::string*>(userp)); do { spacePos = statistics.find(search, currPos); if (spacePos >= 0) { currPos = spacePos; arr[k] = statistics.substr(prevPos, currPos - prevPos); currPos++; prevPos = currPos; k++; } } while (spacePos >= 0); arr[k] = statistics.substr(prevPos, statistics.length()); for (int i = 0; i < k; i++) { std::cout << arr[i] << std::endl; } a = arr[3]; b = arr[2]; c = arr[1]; d = arr[0]; const char *data; time_t now = time(0); char* dt = ctime(&now); const char *payload_text[] = { "Date: ", dt, "\r\n", "To: ",mail.c_str(), "\r\n", "From: " FROM "\r\n", "Subject: Analysis\r\n", "\r\n", "This is just a test message.\r\n", "\r\n", "A:", a.c_str(), "\r\n", "B:", b.c_str(), "\r\n", "C:", c.c_str(), "\r\n", NULL }; if ((size == 0) || (nmemb == 0) || ((size*nmemb) < 1)) { return 0; } data = payload_text[lines_read]; if (data) { size_t len = strlen(data); memcpy(ptr, data, len); lines_read++; return len; } return 0; } void Process::sendmail(std::string mail) { CURL *curl; CURLcode res = CURLE_OK; struct curl_slist *recipients = NULL; curl = curl_easy_init(); if (curl) { curl_easy_setopt(curl, CURLOPT_USERNAME, "User Name"); curl_easy_setopt(curl, CURLOPT_PASSWORD, "Password"); curl_easy_setopt(curl, CURLOPT_URL, "smtp.hushmail.com:587"); curl_easy_setopt(curl, CURLOPT_USE_SSL, (long)CURLUSESSL_ALL); curl_easy_setopt(curl, CURLOPT_CAINFO, "/path/to/certificate.pem"); curl_easy_setopt(curl, CURLOPT_MAIL_FROM, FROM); recipients = curl_slist_append(recipients, mail.c_str()); curl_easy_setopt(curl, CURLOPT_MAIL_RCPT, recipients); curl_easy_setopt(curl, CURLOPT_READFUNCTION, &Process::processmail); curl_easy_setopt(curl, CURLOPT_READDATA, lines_read); curl_easy_setopt(curl, CURLOPT_UPLOAD, 1L); curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L); res = curl_easy_perform(curl); if (res != CURLE_OK) fprintf(stderr, "curl_easy_perform() failed: %s\n", curl_easy_strerror(res)); curl_slist_free_all(recipients); curl_easy_cleanup(curl); } }