By setting up the C++builder component, we can create our own POP3 email receiver.
I. Establishment of a project document
Second, create a new form, set its Caption property to Getmail, place a Tpagecontrol control above it, and right-click to create three Tabsheet (1,2,3). Place four edit (1,2,3,4) controls on the TabSheet1 and clear their text properties and two botton (1,2), where Edit1 is used to enter the name of the POP3 server; Edit2 to set the access port number, we set it to 110, and set its Text property to 110;edit3 to enter the username; Edit4 to enter the password. The caption for Botton1 is "connection" and the Botton2 caption is "Disconnected." Place five edit (5,6,7,8,9) controls, two memo controls, and three botton (3,4,5) on the TabSheet2, Edit5 to display the number of messages, EDIT6, EDIT7, Edit8, and Edit9 to display the sender of the message, The subject, size, and ID number of the message; Memo1 is used to display the body of the message; Memo2 is used to display the message headers, Botton3, Botton4, Botton5 caption properties are set to delete, mail, and mail messages, respectively. Place two botton and one memo control on the TabSheet3, where the caption property of Botton6 is "mailing List"; Botton7 is "purge list"; caption's purpose is naturally to display mailing lists. Place a StatusBar control at the bottom of the form to display the working state. Finally, the most important thing is to place a NMPOP3 control on the form, which is the core of our communication with the POP3 server.
Third, write code
Write code for the onclick event for Botton1:
Nmpop31-〉attachfilepath =″.″; Set the directory where messages are stored
Nmpop31-〉deleteonread = false; Whether to delete after reading the message
Nmpop31-〉reportlevel = Status_basic; Control the number of data reported by the Onstatus event and Status property
Nmpop31-〉timeout = 20000; Set Time to timeout
Nmpop31-〉host = Edit1-〉text; Set the host name of the POP3 server
Nmpop31-〉port = Strtoint (Edit2-〉text); Set the port number of the POP3 server
Nmpop31-〉userid = Edit3-〉text; Get user Name
Nmpop31-〉password = Edit4-〉text; Get the password
Nmpop31-〉connect (); Start connection
Label10-〉caption =″# of Messages:″+inttostr (Nmpop31-〉mailcount); Show the number of messages
Write code for the onclick event for Botton2:
Nmpop31-〉disconnect (); Enable it to disconnect from the server
Write code for the Botton3 onclick event, and delete the message when you click it:
Nmpop31-〉deletemailmessage (Strtoint (Edit5-〉text));
Write code for the Botton4 onclick event that displays the entire message when clicked:
Nmpop31-〉getmailmessage (Strtoint (Edit5-〉text));
Edit6-〉text = Nmpop31-〉mailmessage-〉from; The sender is obtained by MailMessage from attribute
Edit7-〉text = Nmpop31-〉mailmessage-〉subject; Get the theme through the MailMessage Subjecet property
Edit9-〉text = Nmpop31-〉mailmessage-〉messageid; Get ID through MailMessage's Messageids property
Memo2-〉lines-〉assign (Nmpop31-〉mailmessage-〉head);
Memo1-〉lines-〉assign (Nmpop31-〉mailmessage-〉body);
if (Nmpop31-〉mailmessage-〉attachments-〉text!=″″)
ShowMessage (″attachments:\n″+nmpop31-〉mailmessage-〉attachments-〉text);
Write code for the Botton5 onclick event that will display the message's profile in memo when clicked:
Nmpop31-〉getsummary (Strtoint (Edit5-〉text));
Edit6-〉text = Nmpop31-〉summary-〉from;
Edit7-〉text = Nmpop31-〉summary-〉subject;
Edit8-〉text = IntToStr (nmpop31-〉summary-〉bytes);
Edit9-〉text = Nmpop31-〉summary-〉messageid;
Write code for the Botton6 onclick event that will display the mailing list in Memo3 when clicked:
Nmpop31-〉list (); Get a list of the number and size of messages
Write code for the Botton7 onclick event that will clear the mailing list in Memo3 when clicked:
Memo3-〉clear ();