1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
|
#include <iostream>
#include <winsock.h> // Windows Sockets... Required by MySQL API
using namespace std;
SOCKET sock = 0;
void process( char * buffer )
{
Sleep( 500 );
int size = strlen( buffer );
int retVal = send( sock, buffer, size, 0 );
char buf[ 1024 ];
buf[0] = 0x00;
while( !buf[0] )
{
int yeah = recv(sock, buf, 1024, 0 );
}
cout << "RECEIVED > " << buf;
cout << "SENT < " << buffer;
}
int main(int argc, char *argv[])
{
WSADATA wsaData;
if(WSAStartup(0x0101, &wsaData) != 0)
{
cout << endl << "*** WSAStartup() failed ! ***" << endl;
WSACleanup(); // just in case ...
exit(0);
}
else
{
cout << endl << "*** WSAStartup() success ! ***" << endl;
SOCKADDR_IN sin;
sin.sin_addr.s_addr = inet_addr("192.168.1.2");
sin.sin_family = AF_INET;
sin.sin_port = htons(25);
sock = socket(AF_INET,SOCK_STREAM,0);
if (sock < 0)
{
cout << "*** Could not open the TCP socket ! ***" << endl;
exit(0);
}
else
{
cout << "*** TCP socket ok ! ***" << endl;
connect(sock, (SOCKADDR *)&sin, sizeof(sin));
process("HELO TEST\r\n");
process("MAIL From:<me.myself@mail.com>\r\n");
process("RCPT To:<admin@xeena.be>\r\n");
// process("X-Priority: Normal\r\n");
// process("X-Sender: The header tester\r\n");
// process("MIME-Version: 1.0\r\n");
// process("Content-Type: text/plain;charset=\"iso-8859-1\"\r\n");
// process("Content-Transfer-Encoding: 8bit\r\n");
process("DATA\r\n");
process("Subject:test test\r\n\r\n");
process("test test test\r\n.\r\n");
process("QUIT\r\n");
closesocket(sock);
WSACleanup();
}
}
return 0;
} |