I don't know what to declare MBICON_ERROR
or sendToSock
in this script. I'm trying to get the program to send me messages and text file attachments through email from the desktop silently.
#include <winsock2.h>
#include <ws2tcpip.h>
#pragma comment(lib, "Ws2_32.lib")
#include <string.h>
#include <string>
using std::string;
static void InitializeWinSock()
{
WSADATA wsaData;
int iResult = WSAStartup(MAKEWORD(2, 2), &wsaData);
if (iResult != 0) {
MessageBox(NULL, "Unable to initialize WinSock", "Initialization Error", MBICON_ERROR | MB_OK);
exit(0);
}
}
SOCKET openSocketToServer(const std::string& addr, int port)
{
// open socket ...
}
#define MAIL_SERVER_IP "127.0.0.1"
#define MAIL_SERVER_PORT 25
void sendMail(const string& mailTo, const string& mailFrom, const string& subject, const string& body)
{
InitializeWinSock();
SOCKET servSock = openSocketToServer(MAIL_SERVER_IP, MAIL_SERVER_PORT);
sendToSock(servSock, "HELO sender", "");
sendToSock(servSock, "MAIL FROM: ", mailFrom.c_str());
sendToSock(servSock, "RCPT TO: ", mailTo.c_str());
sendToSock(servSock, "DATA", "");
sendToSock(servSock, "From: ", mailFrom.c_str());
sendToSock(servSock, "To: ", mailTo.c_str());
sendToSock(servSock, "Subject: ", subject);
sendToSock(servSock, "", ""); // blank line.
sendToSock(servSock, body.c_str(), "");
sendToSock(servSock, ".", "");
sendToSock(servSock, "quit", "");
}
Aucun commentaire:
Enregistrer un commentaire