Void CSendMailClientDlg: : OnBnClickedSetup ()
{
//TODO: add the control notification handler code
CSetup DLG.
DLG. M_strServer=m_strSmtpSrvName;
DLG. M_strPort=m_strPort;
DLG. M_strUser=m_szUser;
DLG. M_strPwd=m_szPwd;
If (DLG) DoModal ()==IDOK)
{
M_strSmtpSrvName=DLG. M_strServer;
M_strPort=DLG. M_strPort;
Sprintf (m_szUser, "% s", DLG. M_strUser);
Sprintf (m_szPwd, "% s", DLG. M_strPwd);
}
}
Void CSendMailClientDlg: : OnBnClickedOk ()
{
The UpdateData (TRUE);
Const int buflen=256;
Char buf [buflen];
Int I, userlen passlen;
//to the network connection
WSADATA WSADATA;
If (WSAStartup (MAKEWORD (2, 2), & amp; Wsadata)!=0)
{
AfxMessageBox (" WSAStartup Error!" );
return;
}
//create a socket
The SOCKET sockid;
If ((sockid=socket (AF_INET SOCK_STREAM, 0))==INVALID_SOCKET)
{
AfxMessageBox (" Sockid Error!" );
WSACleanup ();
return;
}
//get the SMTP server IP
Struct hostent * phostent=gethostbyname (m_strSmtpSrvName);
Struct sockaddr_in addr.
CopyMemory (& amp; Addr. Sin_addr. S_addr phostent - & gt; H_addr_list [0], sizeof (addr. Sin_addr. S_addr));
Addr. Sin_family=AF_INET;
Addr. Sin_port=htons (atoi (m_strPort));
ZeroMemory (& amp; Addr. Sin_zero, 8);
//connect to the server
If (connect (sockid, (struct sockaddr *) & amp; Addr, sizeof (struct sockaddr_in))==SOCKET_ERROR)
{
AfxMessageBox (" the connect () error!" );
Goto STOP;
}
If (Talk (sockid, "220", "HELO asdf"))
{
Goto STOP;
}
If (Talk (sockid, "250", "AUTH LOGIN"))
{
Goto STOP;
}
ZeroMemory (buf, buflen);
Userlen=strlen (m_szUser);
Passlen=strlen (m_szPwd);
for(i=0; i <(userlen % 3? Userlen/3 + 1: userlen/3); I++)
{
Base64 (unsigned char (*) (m_szUser + I * 3), (unsigned char *) (buf + I * 4));
}
If (Talk (sockid, "334", buf))
{
Goto STOP;
}
ZeroMemory (buf, buflen);
for(i=0; i <(passlen % 3? Passlen/3 + 1: passlen/3); I++)
{
Base64 (unsigned char (*) (m_szPwd + I * 3), (unsigned char *) (buf + I * 4));
}
If (Talk (sockid, "334", buf))
{
Goto STOP;
}
ZeroMemory (buf, buflen);
Wsprintf (buf, "MAIL FROM: & lt; % s>" , m_strFrom);
If (Talk (sockid, "235", buf))
{
Goto STOP;
}
ZeroMemory (buf, buflen);
Wsprintf (buf, "RCPT, & lt; % s>" , m_strTo);
If (Talk (sockid, "250", buf))
{
Goto STOP;
}
If (Talk (sockid, "250", "DATA"))
{
Goto STOP;
}
ZeroMemory (buf, buflen);
Wsprintf (buf, "\ r \ nFROM the TO: % s: % s \ r \ nSUBJECT: % s \ r \ n % s \ r \ n \ r \ n",
M_strTo m_strFrom, m_strSubject m_strMsg);
If (Talk (sockid, "354", buf))
{
Goto STOP;
}
If (Talk (sockid, "250", "QUIT"))
{
Goto STOP;
}
If (Talk (sockid, "221", ""))
{
Goto STOP;
}
STOP:
Shutdown (sockid SD_BOTH);
Closesocket (sockid);
WSACleanup ();
return;
}
Int CSendMailClientDlg: : Talk (SOCKET sockid, const char * OkCode, char * pSend)
{
Const int buflen=256;
Char buf [buflen];
ZeroMemory (buf, buflen);
//receive return information
If (recv (sockid, buf, buflen, 0)==SOCKET_ERROR)
{
Int I=GetLastError ();
AfxMessageBox (" recv () error!" );
return 1;
}
//send the command
If (lstrlen (pSend))
{
ZeroMemory (buf, buflen);
Wsprintf (buf, "% s \ r \ n", pSend);
If (send (sockid, buf, lstrlen (buf), 0)==SOCKET_ERROR)
{
AfxMessageBox (" the send () error ");
return 1;
}
}
return 0;
}
Void CSendMailClientDlg: : Base64 (unsigned char * chasc, unsigned char * chuue)
{
Int I, k=2;
Unsigned char t=0;
for(i=0; i<3; I++)
{
* (chuue + I)=* (chasc + I) & gt;> k;
* (chuue + I) |=t;
T=* (chasc + I) & lt; & lt; (8 k);
T>=2;
K +=2;
}
* (chuue + 3)=* (chasc + 2) & amp; 63;
for(i=0; i<4. I++)
If ((* (chuue + I) & gt;=0) & amp; & (* (chuue + I) & lt;=25))
* (chuue + I) +=65;
Else if ((* (chuue + I) & gt;=26) & amp; & (* (chuue + I) & lt;=51))
* (chuue + I) +=71;
Else if ((* (chuue + I) & gt;=52) & amp; & (* (chuue + I) & lt;=61))
* (chuue + I) -=4;
Else if (* (chuue + I)==62)
* (chuue + I)=43;
Else if (* (chuue + I)==63)
* (chuue + I)=47;
}
CodePudding user response:
Would you like to write a virus to steal people's information?