Я пытаюсь отправить электронное письмо по протоколу SMTP и повысить библиотеки
но по какой-то причине я не могу подключиться к серверу hotmail smtp и отправить письмо самому себе.
это мой код:
что я делаю не так?
DNS_RECORD* ppQueryResultsSet = NULL;
// dns mx lookup
DnsQuery(L"hotmail.com", DNS_TYPE_MX, DNS_QUERY_STANDARD, NULL, &ppQueryResultsSet, NULL);
if (ppQueryResultsSet == NULL)
return false;
// i am getting the mx servers (i.e: mx3.hotmail.com)
wcout << "MX Host name: " << ppQueryResultsSet->Data.MX.pNameExchange << endl;
DnsRecordListFree(ppQueryResultsSet, DnsFreeRecordList);
string host_name = String_Convertion::WStringToString(ppQueryResultsSet->Data.MX.pNameExchange);
// setting up socket connection
boost::asio::io_service io_service;
tcp::resolver resolver(io_service);
tcp::resolver::query query(host_name, "25");
tcp::resolver::iterator endpoint_iterator = resolver.resolve(query), end;
tcp::socket socket(io_service);
// connecting to the server
boost::system::error_code error_code_connect;
boost::asio::connect(socket, endpoint_iterator, end, error_code_connect);
if (error_code_connect)
{
cout << "Error connecting to SMTP Server" << endl;
return false;
}
boost::system::error_code error;
std::string temp_buf;
boost::array<char, 128> buf;
size_t len;
// settings the packets to send
list<string> packets;
packets.push_back("HELO");
packets.push_back("MAIL FROM: xxx@xxx.xxx");
packets.push_back("VRFY xxx@xxx.xxx");
packets.push_back("RCPT TO: x@hotmail.com");
packets.push_back("DATA");
packets.push_back("Subject: subject!");
packets.push_back("hi how are you doing?.");
packets.push_back("QUIT");
list<string>::iterator it;
// iterating to send the packets
for (it = packets.begin(); it != packets.end(); it++)
{
socket.write_some(boost::asio::buffer(*it+"\r\n"));
len = socket.read_some(boost::asio::buffer(buf), error);
temp_buf = buf.data();
temp_buf = temp_buf.substr(0, len);
cout << temp_buf << endl;
}