miki3 Temat założony przez niniejszego użytkownika |
SMTP odmowa połączenia » 2015-07-15 14:46:28 http://www.ssstudios.ovh.org/?id=108 Mam sobie taki kod na stronie i próbuje wysłać nim e-mail, ale nie mam pojęcia czemu utykam w pętli przy próbie połączenia zmieniło się coś od 2015 roku w protokole czy co, czemu nie łączy ?? #include "sendmail.hpp"
int main() { mail( "odbiorca@migmail.pl ", "TITLE", "Dobry" ); return 0; }
#include <winsock.h> #include <stdio.h> #include <windows.h>
#include "sendmail.hpp" #include "base64.hpp" using namespace std;
int mail( std::string to, std::string subject, std::string body ) { printf( "YO in send\n" ); const std::string host = "poczta.interia.pl"; const std::string log = "******@interia.pl"; const std::string pass = "321321a"; const std::string sender = log; const std::string recipient = to; body = "From: Tajemniczy <" + sender + ">" "\nSubject: " + subject + "\nTo: <" + to + ">" "\n\n" + body; const int bufsize = 1024; char response[ bufsize ]; std::string login = base64_encode( reinterpret_cast < const unsigned char *>( log.c_str() ), log.length() ); std::string password = base64_encode( reinterpret_cast < const unsigned char *>( pass.c_str() ), pass.length() ); WORD sockV; WSAData wsaData; int nret; sockV = MAKEWORD( 2, 2 ); WSAStartup( sockV, & wsaData ); LPHOSTENT hostEntry; hostEntry = gethostbyname( host.c_str() ); if( !hostEntry ) { WSACleanup(); printf( "Return err hostEntry 0\n" ); return 0; } SOCKET CData; CData = socket( AF_INET, SOCK_STREAM, IPPROTO_TCP ); if( CData == INVALID_SOCKET ) { WSACleanup(); printf( "Return err CData 0\n" ); return 0; } SOCKADDR_IN ServerInfo; ServerInfo.sin_family = AF_INET; ServerInfo.sin_addr = *(( LPIN_ADDR ) * hostEntry->h_addr_list ); ServerInfo.sin_port = htons( 25 ); nret = connect( CData,( LPSOCKADDR ) & ServerInfo, sizeof( struct sockaddr ) ); while( nret == SOCKET_ERROR ) { printf( "Retry connect %s\n", host.c_str() ); nret = connect( CData,( LPSOCKADDR ) & ServerInfo, sizeof( struct sockaddr ) ); } recv( CData, response, bufsize, 0 ); printf( "Odpowiedz: %s\n", response ); memset( & response, 0, bufsize ); send( CData,( "ehlo " + host + "\r\n" ).c_str(),( "ehlo " + host + "\r\n" ).length(), 0 ); recv( CData, response, bufsize, 0 ); printf( "Odpowiedz: %s\n", response ); memset( & response, 0, bufsize ); send( CData, "AUTH LOGIN\r\n", strlen( "AUTH LOGIN\r\n" ), 0 ); recv( CData, response, bufsize, 0 ); printf( "Odpowiedz: %s\n", response ); memset( & response, 0, bufsize ); send( CData,( login + "\r\n" ).c_str(), login.length() + 2, 0 ); recv( CData, response, bufsize, 0 ); printf( "Odpowiedz: %s\n", response ); memset( & response, 0, bufsize ); send( CData,( password + "\r\n" ).c_str(), password.length() + 2, 0 ); recv( CData, response, bufsize, 0 ); printf( "Odpowiedz: %s\n", response ); memset( & response, 0, bufsize ); send( CData,( "MAIL FROM: <" + log + ">\r\n" ).c_str(),( "MAIL FROM: <" + log + ">\r\n" ).length(), 0 ); recv( CData, response, bufsize, 0 ); printf( "Odpowiedz: %s\n", response ); memset( & response, 0, bufsize ); send( CData,( "RCPT TO: <" + recipient + ">\r\n" ).c_str(),( "RCPT TO: <" + recipient + ">\r\n" ).length(), 0 ); recv( CData, response, bufsize, 0 ); printf( "Odpowiedz: %s\n", response ); memset( & response, 0, bufsize ); send( CData, "DATA\r\n", 6, 0 ); recv( CData, response, bufsize, 0 ); printf( "Odpowiedz: %s\n", response ); memset( & response, 0, bufsize ); send( CData, body.c_str(), body.length(), 0 ); send( CData, "\r\n.\r\n", 5, 0 ); recv( CData, response, bufsize, 0 ); printf( "Odpowiedz: %s\n", response ); memset( & response, 0, bufsize ); send( CData, "quit\r\n", 6, 0 ); recv( CData, response, bufsize, 0 ); printf( "Odpowiedz: %s\n", response ); return 1; }
|