Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _WINSOCK_DEPRECATED_NO_WARNINGS
- #define _CRT_SECURE_NO_WARNINGS
- #include <WinSock2.h>
- #include <Windows.h>
- #include <conio.h>
- #include <iostream>
- #include <string>
- #include <ctime>
- #include <fstream>
- #pragma comment(lib, "ws2_32.lib")
- using namespace std;
- #define MAX_MSG 128
- #define CRLF "\r\n"
- string senderMail = "testpop3test1@wp.pl", reciverMail = "psulzyc@wi.zut.edu.pl", serverSMTP = "smtp.wp.pl", emailwbase64 = "dGVzdHBvcDN0ZXN0MUB3cC5wbA==", haslowbase64 = "VGVzdHBvcDM=" ;
- string plain = "PLAIN";
- string login = "LOGIN";
- int port = 587;
- int main()
- {
- SOCKET sock_on;
- WSADATA wsaData;
- LPHOSTENT lpHostEntry;
- LPSERVENT lpServEntry;
- SOCKADDR SockAddr;
- struct sockaddr_in sok = { 0 };
- struct hostnet *hp;
- string command, s, msg_num;
- char buff[MAX_MSG];
- int n_bytes = 0;
- char szMsgLine[255] = "";
- int iProtocolPort = 0;
- if (WSAStartup(MAKEWORD(2, 2), &wsaData))
- {
- cout << "Cannot find Winsock v" << 2 << "." << 2 << " or later!" << endl;
- return 1;
- }
- // Lookup email server's IP address.
- lpHostEntry = gethostbyname(serverSMTP.c_str());
- if (!lpHostEntry)
- {
- cout << "canoot find SMTP mail server" << serverSMTP << endl;
- return 1;
- }
- //sock_on = socket(AF_INET, SOCK_STREAM, 0); // init socket
- sock_on = socket(PF_INET, SOCK_STREAM, 0);
- sok.sin_family = AF_INET;
- sok.sin_addr = *((LPIN_ADDR)*lpHostEntry->h_addr_list);
- sok.sin_port = (unsigned short int) htons(port);
- //------------------------------------------------------------------------------------
- if ((connect(sock_on, (sockaddr *)&sok, sizeof(sockaddr_in))))
- {
- cout << "nie udało się " << endl;
- }
- n_bytes = recv(sock_on, buff, MAX_MSG, 0);
- //cout << buff<<", "<< n_bytes << endl;
- //------------------------------------------------------
- sprintf(szMsgLine, "EHLO %s%s", serverSMTP.c_str(), CRLF);
- n_bytes = send(sock_on, szMsgLine, strlen(szMsgLine), 0);
- cout << n_bytes << endl;
- n_bytes = recv(sock_on, buff, sizeof(buff), 0);
- cout << buff << ", " << n_bytes << endl;
- //---------------------------------------------------------------------------------------------
- sprintf(szMsgLine, "AUTH %s%s", login.c_str(), CRLF);
- n_bytes = send(sock_on, szMsgLine, strlen(szMsgLine), 0);
- cout << n_bytes << endl;
- n_bytes = recv(sock_on, buff, sizeof(buff), 0);
- cout << buff << ", " << n_bytes << endl;
- //-----------------------------------------------------------------------------------------------
- string mailiN = "dGVzdHBvcDN0ZXN0MUB3cC5wbA==";
- string hasloN = "VGVzdHBvcDM=";
- //-------------------------------------------------------------------------------------------------
- sprintf(szMsgLine, "%s%s", mailiN.c_str(), CRLF);
- n_bytes = send(sock_on, szMsgLine, strlen(szMsgLine), 0);
- cout << n_bytes << endl;
- n_bytes = recv(sock_on, buff, sizeof(buff), 0);
- cout << buff << endl;
- //-----------------------------------------------------------------------------------------------
- sprintf(szMsgLine, "%s%s", hasloN.c_str(), CRLF);
- n_bytes = send(sock_on, szMsgLine, strlen(szMsgLine), 0);
- cout << n_bytes << endl;
- n_bytes = recv(sock_on, buff, sizeof(buff), 0);
- cout << buff << endl;
- //----------------------------------------------------------------- //
- sprintf(szMsgLine, "MAIL FROM:<%s>%s", senderMail.c_str(), CRLF);
- n_bytes = send(sock_on, szMsgLine, strlen(szMsgLine),0);
- cout << n_bytes << endl;
- n_bytes = recv(sock_on, buff, sizeof(buff), 0);
- cout << buff << ", " << n_bytes << endl;
- //------------------------------------------------------
- sprintf(szMsgLine, "RCPT TO:<%s>%s", reciverMail.c_str(), CRLF);
- n_bytes = send(sock_on, szMsgLine, strlen(szMsgLine), 0);
- cout << n_bytes << endl;
- n_bytes = recv(sock_on, buff, sizeof(buff), 0);
- cout << buff << endl << n_bytes << endl;
- //-------------------------------------------------------
- sprintf(szMsgLine, "DATA%s", CRLF);
- n_bytes = send(sock_on, szMsgLine, strlen(szMsgLine), 0);
- cout << n_bytes << endl;
- n_bytes = recv(sock_on, buff, sizeof(buff), 0);
- cout << buff << endl;
- string testwiadomosc = "testpop3test1@wp.pl";
- sprintf(szMsgLine, "FROM: %s%s", testwiadomosc.c_str(), CRLF);
- send(sock_on, szMsgLine, strlen(szMsgLine), 0);
- testwiadomosc = "data";
- sprintf(szMsgLine, "Date: %s%s", testwiadomosc.c_str(), CRLF);
- send(sock_on, szMsgLine, strlen(szMsgLine), 0);
- testwiadomosc = "Temat";
- sprintf(szMsgLine, "Subject: %s%s", testwiadomosc.c_str(), CRLF);
- send(sock_on, szMsgLine, strlen(szMsgLine), 0);
- testwiadomosc = "test smtptest";
- sprintf(szMsgLine, "%s%s", testwiadomosc.c_str(), CRLF);
- send(sock_on, szMsgLine, strlen(szMsgLine), 0);
- testwiadomosc = "test smtptest";
- sprintf(szMsgLine, "%s%s", testwiadomosc.c_str(), CRLF);
- send(sock_on, szMsgLine, strlen(szMsgLine), 0);
- sprintf(szMsgLine, "%s%s", testwiadomosc.c_str(), CRLF);
- send(sock_on, szMsgLine, strlen(szMsgLine), 0);
- //-----------------------------------------------------
- sprintf(szMsgLine, "%s.%s", CRLF, CRLF);
- n_bytes = send(sock_on, szMsgLine, strlen(szMsgLine), 0);
- cout << n_bytes << endl;
- n_bytes = recv(sock_on, buff, sizeof(buff), 0);
- cout << buff << endl;
- //-----------------------------------------------------
- // Send QUIT
- sprintf(szMsgLine, "QUIT%s", CRLF);
- send(sock_on, szMsgLine, strlen(szMsgLine), 0);
- recv(sock_on, buff, sizeof(buff), 0);
- cout << buff << endl;
- cout << "Sent as email message to " << reciverMail << endl;
- closesocket(sock_on);
- getchar();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement