Я скомпилировал пример c, который поставляется с libcurl.
Исходный файл smtp-tls.c
Пытался использовать его для отправки почты через gmail, и вот что я получил
- О подключении() к порту smtp.gmail.com 465 (#0)
- Попытка 74.125.115.109... * подключена
- #P2# <блочная цитата> #P3# блочная цитата>
Пустой ответ от сервера
- Соединение №0 с хостом smtp.gmail.com осталось нетронутым
- Сервер ничего не вернул (ни заголовков, ни данных)
- Закрытие соединения #0
Что я пропустил? Я никак не модифицировал код, кроме ввода переменных. На этом компьютере я могу отправлять и получать почту с помощью Outlook 2003.
ИЗМЕНИТЬ
Пробовал другой порт. Вот результат
- О подключении() к порту smtp.gmail.com 587 (#0)
- Попытка 74.125.93.109... * подключена
- Server auth using Basic with user '[email protected]'
GET / HTTP/1.1 Authorization: Basic xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx Host: smtp.gmail.com:587 Accept: /
220 mx.google.com ESMTP ew54y2x5of95qdz.12 502 5.5.1 Unrecognized command. ew54y2x5of95qdz.12 * Connection #0 to host smtp.gmail.com left intact * Closing connection #0
ИЗМЕНИТЬ
Главное выглядит так
int main()
{
CURL *curl;
CURLcode res;
struct curl_slist *recipients = NULL;
struct upload_status upload_ctx;
upload_ctx.lines_read = 0;
curl = curl_easy_init();
if (curl) {
curl_easy_setopt(curl, CURLOPT_URL, "smtp://gmail.com:587");
curl_easy_setopt(curl, CURLOPT_USE_SSL, CURLUSESSL_ALL);
curl_easy_setopt(curl, CURLOPT_USERNAME, "[email protected]");
curl_easy_setopt(curl, CURLOPT_PASSWORD, "xxxxxxxx");
curl_easy_setopt(curl, CURLOPT_MAIL_FROM, FROM);
recipients = curl_slist_append(recipients, TO);
recipients = curl_slist_append(recipients, CC);
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_VERBOSE, 1);
res = curl_easy_perform(curl);
curl_slist_free_all(recipients);
curl_easy_cleanup(curl);
}
return 0;
}
ИЗМЕНИТЬ
Похоже, правильный URL-адрес должен быть smtp://smtp.gmail.com:587
Это продвинуло меня дальше, теперь я получаю
* About to connect() to smtp.gmail.com port 587 (#0)
* Trying 74.125.45.108... * connected
< 220 mx.google.com ESMTP j26srtuiopnann.7
> EHLO my_computer_name
< 250-mx.google.com at your service,
< 250-SIZE 35882577
< 250-8BITMIME
< 250-STARTTLS
< 250 ENHANCEDSTATUSCODES
* No known auth mechanisms supported!
> QUIT
< 221 2.0.0 closing connection j26srtuiopnann.7
* Closing connection #0
* Login denied
EDIT
Libcurl не поддерживает SSL