Lets say I have a function like below that sends and receives info from a socket flawlessly..
The results are:
Connected to: 65.55.96.11 Port: 25
220 BLU0-SMTP374.blu0.hotmail.com Microsoft ESMTP MAIL Service, Version: 6.0.3790.4675 ready at Mon, 31 Dec 2012 19:52:22 -0800
250 BLU0-SMTP374.blu0.hotmail.com Hello [50.100.44.155]
220 2.0.0 SMTP server ready
Exception: Socket Error 10054: Connection reset by peer
Why do I get an exception? It throws the exception when I send the “DATA” string.
How do I login? I cannot seem to find out how anywhere online. I searched it and only see AUTH command but no usage or examples at all.
The code is below:
void SendEmail(std::string Username, std::string Password, std::string IP, std::string Port)
{
Socket = CreateSocket;
ConnectSocket(Socket, IP, Port);
SetTimeout(Socket, 10000);
SocketInfo(Socket, IP, Port);
writeln("Connected to: " + IP + " Port: " + Port);
writeln(RecvSocket(Socket));
SendSocketEx(Socket, "HELO"); //SendSocketEx automatically adds \r\n to the end of a line..
writeln(RecvSocket(Socket));
SendSocketEx(Socket, "STARTTLS");
writeln(RecvSocket(Socket));
SendSocketEx(Socket, "MAIL FROM: mehwtfbleh@hotmail.com");
writeln(RecvSocket(Socket));
SendSocketEx(Socket, "VRFY mehwtfbleh@hotmail.com");
writeln(RecvSocket(Socket));
SendSocketEx(Socket, "RCPT TO: mehwtfbleh@hotmail.com");
writeln(RecvSocket(Socket));
SendSocketEx(Socket, "DATA");
writeln(RecvSocket(Socket));
SendSocketEx(Socket, "This Is The Body..");
writeln(RecvSocket(Socket));
SendSocketEx(Socket, "QUIT");
writeln(RecvSocket(Socket));
CloseSocket(Socket);
FreeSocket(Socket);
}
int main()
{
SendEmail("", "", "smtp.live.com", "25", "localhost");
}
The problem is that this server requires communication to occur over the TLS protocol. The STARTTLS command tells the server that all further communication will occur over the Secure Sockets Layer (SSL/TLS). Once this connection is established, all further communication between the 2 sides is encrypted.
The easiest way to accomplish that is to use a library that implements SSL/TLS. The most famous library is OpenSSL.
You can perform a quick test using OpenSSL from your terminal/console:
Then you can send your commands: