C++ CURL Segmentation fault
Пытаюсь отправить с помощью CURL emal почту в формате HTML. Программа падает с ошибкой Segmentation fault в процедуре payload_source. Все дело в том что в переменной message слишком много букв. Может есть какие настройки у CURL для отправки больших сообщений?
string message = "Очень длинная строка около 70000 знаков";
Mailer::Send(m_MailerAccount, "[email protected]", "[email protected]", "Тут тема", message);
int Mailer::Send(MailerAccount& account, std::string from, std::string to, std::string subject, std::string message, MAILER_CONTENT_TYPE contentType) {
CURL* curl;
CURLcode res;
struct curl_slist* recipients = NULL;
curl = curl_easy_init();
queue<string> msg = init_message(to, from, subject, message, contentType);
if (curl) {
curl_easy_setopt(curl, CURLOPT_URL, account.url.c_str()); //"smtps://smtp.yandex.ru:465"
curl_easy_setopt(curl, CURLOPT_USERNAME, account.login.c_str());
curl_easy_setopt(curl, CURLOPT_PASSWORD, account.password.c_str());
curl_easy_setopt(curl, CURLOPT_MAIL_FROM, from.c_str());
curl_easy_setopt(curl, CURLOPT_INFILESIZE, message.size());
recipients = curl_slist_append(recipients, to.c_str());
curl_easy_setopt(curl, CURLOPT_MAIL_RCPT, recipients);
curl_easy_setopt(curl, CURLOPT_READFUNCTION, payload_source);
curl_easy_setopt(curl, CURLOPT_READDATA, &msg);
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);
curl_easy_setopt(curl, CURLOPT_UPLOAD, 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);
}
return 0;
}
static long long payload_source(void* ptr, long long size, long long nmemb, void* userp) {
queue<string>* msg = (queue<string>*)userp;
if (msg->empty()) {
return 0;
}
else {
string s = "";
s = msg->front();
msg->pop();
memcpy(ptr, s.c_str(), s.size());
return s.size();
}
return 0;
}
queue<string> init_message(string to, string from, string subj, string message, MAILER_CONTENT_TYPE contentType) {
queue<string> msg;
string s = "To: " + to + "\n";
msg.push(s);
s = "From: " + from + "\n";
msg.push(s);
s = "Subject: " + subj + "\n";
msg.push(s);
if (contentType == MAILER_CONTENT_TYPE::MCT_HTML) {
msg.push(message);
}
else {
s = "\n";
msg.push(s);
msg.push(message);
}
return msg;
}