By settings to C Builder, we can create your own POP3 email receiver.
First, establish a project file
Second, establish a new form, set its CAPTION property as getmail, place a TPAGECONTROL control above, right-click to create three Tabsheets (1, 2, 3). Place four Edit (1, 2, 3, 4) controls on TabSheet1 and clear their text attributes and two Botton (1, 2), where edit1 is used to enter the name of the POP3 server; edit2 is used to set the access port number We set it is 110, and set it to 110; Edit3 is used to enter the username; Edit4 is used to enter a password. The CAPTION of Botton1 is "Connect", and Botton2's CAPTION is "Disconnect". Place five Edit (5, 6, 7, 8, 9) controls on TabSheet2, two MEMO controls and three Botton (3, 4, 5), edit5 to display the number of the message; Edit6, Edit7, Edit8 and EDIT9 is used to display the sender of the message, the subject, the size, and ID number of the message; MEMO1 is used to display the body of the message; MEMO2 is used to display the mail head; Botton3, Botton4, Botton5's CAPTION attribute is set to "Delete", " Email "and" Mail Information ". Place two Botton and a MEMO control on TabSheet3, where the caption property of Botton6 is "Mail List"; Botton7's CAPTION is "Clear List"; MEMO's use is naturally a list of email. Place a STATUSBAR control at the bottom of the form to display a working state. Finally, the most important thing is to place an NMPOP3 control on the form, in this program, it is the core of our communication with the POP3 server.
Third, write code
Write code for Botton1 on the onclick event:
Nmpop31-> attachfilepath = "." // Set the storage directory nmpop31-> deleteonread = false; // After reading the mail, delete NMPOP31-> ReportLevel = status_basic; // Control the ONSTATUS event and the status attribute report information Quantity nmpop31-> timeout = 2000; // Set timeout time nmpop31-> host = edit1-> text; // Set the host name nmpop31-> port = start (edit2-> text); // Set POP3 Server port number nmpop31-> userid = edit3-> text; // get username nmpop31-> password = edit4-> text; // get password nmp31-> connect (); // Start connection label10-> caption = " # of message: " INTTOSTR (nmpop31-> mailcount); // Displays the number of emails
Write code for the Botton2 onclick event:
NMPOP31-> disconnect (); // can be disconnected from the server
Write code for Botton3's OnClick event, you can delete emails when you click on it:
NMPOP31-> DeletemailMessage (strtoint (edit5-> text);
Write the code for the Botton4 onclick event, display the entire email when you click on it:
NMPOP31-> getmailmessage (strt "); edit6-> text = nmpop31-> mailmessage-> from; // Get sender edit7-> text = nmpop31-> mailmessage-> subject; // MailMessage obtained by the attribute relating Subjecet Edit9-> Text = NMPOP31-> MailMessage-> MessageId; // get Id Memo2-> Lines-> Assign (NMPOP31-> MailMessage-> Head) by a MessageIds MailMessage properties; Memo1- > LINES-> Assign (nmpop31-> mailmessage-> body); if (nmpop31-> mailmessage-> attachments-> text! = ") ShowMessage (" attachments: / n " nmpop31-> mailmessage-> attachments-> Text); write code for Botton5 onclick event, click on it, display the outline of the message in MEMO:
NMPOP31-> getSummary (strt "); edit6-> text = nmpop31-> summary-> from; edit7-> text = nmpop31-> summary-> subject; edit8-> text = INTOSTR (nmpop31-> Summary-> bytes; edit9-> text = nmpop31-> summary-> messageId;
Write the code for the Botton6 onclick event, click on it to display the mailing list in MEMO3:
NMPOP31-> list (); // Get the number of emails and the list of sizes
Write code for Botton7's onclick event, click on it, and you will clear the mailing list in Memo3:
Memo3-> clear ();
Write code for NMPOP3 events
1. Write code for its onConnect event
Statusbar1-> SimpleText = "connection"; // After the connection is displayed in the status bar
2. Write code for its onConnectionFailed event
ShowMessage ("Connection Failed"); // Report if the connection failed
3. Write code for its onConnectionRequired event
Ansistring BoxCaption; Ansistring Boxmsg; BoxCaption = "Request to Connection"; BoxMsg = "Request to Connection, Connection?"; IF (MessageBox (0, & Boxmsg [1], & BoxCaption [1], MB_YESNO MB_ICONEXCLAMATION) == iDyes) {handled = True; Form1-> Button1click (this);
4. Write code for its OnDisconnect event
IF (statusbar1! = 0) statusbar1-> simpletext = "disconnected"; // After disconnecting, display is disconnected in the status bar
5. Write code for its onfailuer event
ShowMessage ("Failure!"); 6. Write code for its onHostResovled event
STATUSBAR1-> SimpleText = "Host Resolved";
7. Write code for its OnInvailidHost event
ANSISUSTRING NewHost;
IF ("INPUTQUERY (" Illegal Host Name! "," Please re-enter new host name ", newhost)) {nmpop31-> host = newhost; handled = true;
8. Write code for its online event
IF (MSG <2) {memo3-> clear (); memo3-> lines-> add ("message number / message size");} Memo3-> Lines-> Add (INTTOSTR (MSG) "/" INTOSTR (Size);
9. Write code for its online eventpacketRecvd event
Statusbar1-> SimpleText = INTOSTR (nmpop31-> bytesrecv) "bytesof" INTOSTR (nmpop31-> bytestotal) "received";
10. Write code for its OnReset event
ShowMessage (Reset Delete Sign);
11. Write code for its OnRetrieveEnd event
FORM1-> Cursor = crdefault; statusbar1-> simpletext = "Restore completion";
12. Write code for its onRetriefStart event
Form1-> Cursor = cr HOURGLASS; statusbar1-> simpletext = "Restore start";
13. Write code for its onStatus event
IF (statusbar1! = 0) statusbar1-> simpletext = status;
14. Write code for its onsuccess event
Statusbar1-> SimpleText = "Successful operation".
At this point, our email program is completed, after compiling, enter your POP3 server name, you can receive your email, how? Try it. = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = -
//
__________ / lb / ___ Outinn
/ _ [] _ / ____ / /
/ _________ / | () | / __ /
Http://outinn.yeah.net/
| ____ / - | __ | - / | Welcome to Visit Outinn!
| __ | == | ___ | || | __ |
- = - = - = - | _ || _ | = - FANCY,
Outinn@china.com