Joke Collection Website - Blessing messages - The program is written in Xcode. After the program is run, send me an email to ask for help.

The program is written in Xcode. After the program is run, send me an email to ask for help.

/*

Pure C mail program,

The default is 163 mailbox server, which can be modified,

By default, you need to manually enter the account number and Password,

Change the variable to a constant to automatically log in to the server using a fixed account.

Modify the receiving email account to send emails to the specified email address

Embed other c The c mail function can be implemented in the language code

*/

#include lt; windows.hgt;

#include lt; winsock.hgt;

#include lt;assert.hgt;

#include lt;iostreamgt;

#include lt;stringgt;

#include lt;stdio .hgt;

#include lt;ctimegt;

#pragma comment(lib, "WS2_32.lib")

using namespace std;

//base64 encoding

string Base64Encode(LPCTSTR lpszSrc);

//base64 decoding

string Base64Decode(LPCTSTR lpszSrc);

int main()

{

//1. First, you need to connect to the mail server. Here, use socket mail server port 25

WSADATA Wsa;

p>

//Configure WINSOCK

WSAStartup(0x0101, amp; Wsa);

SOCKET s = socket(AF_INET, SOCK_STREAM, IPPROTO_IP);

SOCKADDR_IN sin;

LPHOSTENT lphost = gethostbyname("smtp.163.com"); //This can also be modified using NetEase's mail server

if(lphost)

sin.sin_addr.s_addr = ((LPIN_ADDR)lphost-gt;h_addr)-gt;s_addr;

else

{

printf("s\n","Failed to obtain address");

return 1;

}

sin.sin_family = AF_INET;

//Pay attention to the listening port 25 of the mail server

sin.sin_port = htons(IPPORT_SMTP);

//Connect to the server

if( connect(s, (LPSOCKADDR)&sin, sizeof(sin))==SOCKET_ERROR)

{

printf("s\n","Connection Error");

return 1;

}

printf("s\n", "Connection successful");

//Receive the server for the first time Response

char buff[1024];

memset(buff, 0, sizeof(buff));

recv(s,

buff, sizeof(buff), 0);

printf("Service said: s\n", buff);

/////The above connection has been completed// ///

string szLine="\r\n"; //Equivalent to pressing Enter

//2. Now you are talking to the server

//Hello server

string szHelo = "HELO smtp.163.com" szLine;

printf("I said: s\n", szHelo.c_str() );

send(s, szHelo.c_str(), szHelo.length(), 0);

memset(buff, 0, sizeof(buff));

recv(s, buff, sizeof(buff), 0);

printf("Service said: s\n", buff);

//Request verification User password (encoding required)

string szAL = "auth login" szLine; //Send verification command

printf("I said: s\n", szAL.c_str() );

send(s, szAL.c_str(), szAL.length(), 0);

memset(buff, 0, sizeof(buff));

recv(s, buff, sizeof(buff), 0);

//printf("Service said: s\n", buff); //The server will reply that it can enter the account number

//Send account

string szUser;

coutlt;lt; Base64Decode((LPCTSTR)(buff 4));

cingt; gt; szUser;

szUser = Base64Encode(szUser.c_str()) szLine; // Base64 encode the input account

send(s, szUser.c_str() , szUser.length(), 0); //Send account

printf("I said: s\n", szUser.c_str());

memset(buff, 0, sizeof(buff));

recv(s, buff, sizeof(buff), 0);

// printf("Service said: s\n", buff ); //The server will reply that you can enter the password

//Send password

string szPsw;

coutlt;lt;Base64Decode((LPCTSTR)(buff 4));

cingt; gt; szPsw;

szPsw = Base64Encode(szPsw.c_str()) szLine; // Base64 encode the entered password

send(s, szPsw.c_str(), szPsw.length(), 0); //Send password

printf("I said: s\n", szPsw.c_str());

memset(buff, 0, sizeof(buff));

recv(s, buff, sizeof(buff), 0);

<

p>printf("Service said: s\n", buff);

//Then you can use the email address you logged in to send emails to other email addresses

string szFrom, szTo;

coutlt;lt;"from:";//your own email

cingt;gt;szFrom;

coutlt;lt;"to:" ; //Who to send to

cingt;gt;szTo;

//Sender's address

string From = "mail from: lt;" szFrom "gt;" szLine;

//Recipient address

string To = "rcpt to:lt;" szTo "gt;" szLine;

/ /Now determine who sent the email to where

send(s, From.c_str(), From.length(), 0); //from

printf(" I said: s\n", From.c_str());

memset(buff, 0, sizeof(buff));

recv(s, buff, sizeof(buff) ), 0);

printf("Service said: s\n", buff);

getchar(); //Just used to pause, press any letter to continue

send(s, To.c_str(), To.length(), 0); //to

printf("I said: s\n", To.c_str( ));

memset(buff, 0, sizeof(buff));

recv(s, buff, sizeof(buff), 0);

printf("Service said: s\n", buff);

getchar();

//You should have read all the information. After inputting the data in the command, it means entering the email. Content

send(s, "data\r\n", 6, 0); //DATA command sent

printf("I said: s\n"," data");

memset(buff, 0, sizeof(buff));

recv(s, buff, sizeof(buff), 0);

printf("Service said: s\n", buff);

//The information below the email is treated as content

//Email header

string szFrom_in = "from:" szFrom szLine;

string szTo_in = "to:" szTo szLine;

//Sending date

string szDate_in= "Date: Sat, 20 Aug 2011 13:39:29 0800" szLine; //Here I will write the date directly for convenience

//Email title

string szSubject_in = "Subject: I am the email title" szLine;

//Email text

string szBody_in = "I am the legendary email body" szLine;

string szContent = szFrom_in szTo_in

szDate_in szSubject_in;

szContent = szLine; //Add a blank line

szContent = szBody_in;

//The above is the most basic format //

send(s, szContent.c_str(), szContent.length(), 0); //szContent

printf("I said: s\n", szContent.c_str() );

memset(buff, 0, sizeof(buff));

// recv(s, buff, sizeof(buff), 0);

// printf("Service said: s\n", buff);

getchar();

//end after sending instructions

send (s, ".\r\n", 3, 0); //The description is over

printf("I said: s\n", ".");

memset(buff, 0, sizeof(buff));

recv(s, buff, sizeof(buff), 0);

printf("Service said: s\ n", buff);

getchar();

//Exit the server connection

send(s, "quit\r\n", 6, 0); //Exit

printf("I said: s\n", "quit");

memset(buff, 0, sizeof(buff));

p>

recv(s, buff, sizeof(buff), 0);

printf("Service said: s sent email successfully\n", buff);

return 0;

}