Mail Retrieval: Using the POP3 Client
Example 24 shows basic POP3 command access. After making a successful connection to a POP3 server and completing login transactions, the program checks for messages in a mail box. If it finds any messages, it gets the first message in the mail drop and displays it on the screen.
NOTE: Servers and files shown in the code might not exist and are included as examples only.
Example 24 – Using the POP3 client
RWPop3Reply reply;
RWPop3StatReply statReply;
RWPop3ConnReply connReply;
try {
RWPop3Client client; // 1
connReply = client.connect("mail.roguewave.com"); // 2
reply = client.user("user"); // 3
reply = client.pass("password"); // 4
statReply = client.stat(); // 5
int totalMsgs = statReply.getMessageCount(); // 6
cout << "The number of messages is : " << totalMsgs << endl;
if (totalMsgs > 0) {
cout << "Let's retrieve the first message." << endl;
dataReply = client.retr(1); // 7
if (!dataReply.isErr()) { // 8
RWSocketPortal portal = dataReply.portal(); // 9
RWPortalIStream istr(portal); //10
RWCString line;
do {
line.readLine(istr); //11
line = rwNormalizeLine(line); //12
if (line != ".") {
cout << line << endl;
}
} while (line != "."); //13
}
}
}
catch (const RWxmsg& msg) { //14
cout << "ERROR: " << msg.why() << endl;
}
This example demonstrates one method of redeeming an
RWTIOUResult object. For other methods, see
Multithreading and IOUs and
File Retrieval: Using the FTP Agent (Part II).