smtp演示
http://www.faqs.org/rfcs/rfc821.html
WSADATA wsa; WSAStartup(MAKEWORD(2,2), &wsa); SOCKET sock = socket(AF_INET, SOCK_STREAM, 0); if (sock == INVALID_SOCKET) { return -1; } struct sockaddr_in addr; addr.sin_addr.s_addr = inet_addr(server); addr.sin_family = AF_INET; addr.sin_port = htons(port); if (connect(sock, (struct sockaddr *)&addr, sizeof(addr))) { closesocket(sock); return -2; } // ehlo char szBuf [SIZE_4K] = {0}; std::string request = "EHLO "; request += server; request += HTTP_CRLF; send(sock, request.c_str(), request.length(), 0); memset(szBuf, 0, SIZE_4K); recv(sock, szBuf, SIZE_4K, 0); // auth login request = "AUTH LOGIN"; request += HTTP_CRLF; send(sock, request.c_str(), request.length(), 0); memset(szBuf, 0, SIZE_4K); recv(sock, szBuf, SIZE_4K, 0); // =------ request = user; request += HTTP_CRLF; send(sock, request.c_str(), request.length(), 0); recv(sock, szBuf, SIZE_4K, 0); request = pass; request += HTTP_CRLF; send(sock, request.c_str(), request.length(), 0); memset(szBuf, 0, SIZE_4K); recv(sock, szBuf, SIZE_4K, 0); // mail from request = "MAIL FROM "; request += mailfrom; request += HTTP_CRLF; send(sock, request.c_str(), request.length(), 0); memset(szBuf, 0, SIZE_4K); recv(sock, szBuf, SIZE_4K, 0); // rcpt to request = "RCPT TO "; request += rcptto; request += HTTP_CRLF; send(sock, request.c_str(), request.length(), 0); memset(szBuf, 0, SIZE_4K); recv(sock, szBuf, SIZE_4K, 0); // data request = "DATA"; request += HTTP_CRLF; send(sock, request.c_str(), request.length(), 0); memset(szBuf, 0, SIZE_4K); recv(sock, szBuf, SIZE_4K, 0); // =----------- request = "From:"; request += mailfrom; request += HTTP_CRLF; request += "To:"; request += rcptto; request += HTTP_CRLF; request += "Subject:"; request += subject; request += HTTP_CRLF; request += "Cc:"; request += cc; request += HTTP_CRLF; request += HTTP_CRLF; request += body; request += HTTP_CRLF; request += "."; request += HTTP_CRLF; send(sock, request.c_str(), request.length(), 0); memset(szBuf, 0, SIZE_4K); recv(sock, szBuf, SIZE_4K, 0); // noop request = "NOOP"; request += HTTP_CRLF; send(sock, request.c_str(), request.length(), 0); memset(szBuf, 0, SIZE_4K); recv(sock, szBuf, SIZE_4K, 0); // quit request = "QUIT"; request += HTTP_CRLF; send(sock, request.c_str(), request.length(), 0); memset(szBuf, 0, SIZE_4K); recv(sock, szBuf, SIZE_4K, 0); closesocket(sock);
pop3演示
http://www.rfc-editor.org/rfc/rfc1939.txt