Web outlook, using pop to receive mail from the mail server

Source: Internet
Author: User

I always wanted to create a Web version of outlook, so I came up with this idea. In fact, I have been familiar with this kind of things before. So I searched for it online and received it through jmail all over the sky. Okay, now that everyone is using it, I will download it and try it.

What, how can I always report errors? It turns out that I was looking for a cracked version, and XXX found a cracked version of jmail4.4. Finally, I had to go into the question. Looking at it, it was quite simple. I typed the code according to the document and ran it at the breakpoint. Yo! Actually, we can continue tracking at the breakpoint step by step. I am X, and the title is garbled. I found the POP Protocol later and checked it out because of the encoding problem.

Okay, we can decode it. After obtaining the source code of the email from jmail, We can decode it .............................. A painful and long process eventually failed. The reason is not detailed. The final result is still a bit problematic, the content will still be garbled, and the attachment will be empty, embedded images cannot be displayed.

 

Well, brother persistently looks for other methods, so he finally finds an "artifact" [aspose. network], this is a charge, after looking for a long time to find a usable version, this component integrates a lot of functions, it seems that the new version has separated the email, but the new version still seems to have garbled characters, so use it.

Note: This article only applies to exercises. Please do not use it for commercial purposes.

 

In fact, it is nothing more than getting the mail title, content, attachments, and senders on the mail server. This component has been provided and is very convenient to use.

Okay. Let's start to explain how to get it!

1. Establish a connection
1 // establish a connection to pop3client (Mail pop, port, user name, password) 2 pop3client POP3 = new pop3client (request. form ["pop"], 110, request. form ["user"], request. form ["pass"]); 3 pop3.connect (true); // connect and log on
2. Get all emails to start traversing and get details
1 int messagecount = pop3.getmessagecount (); // obtain the number of all emails in the target email address. 2 3 // obtain the information of a single email in a loop. 4 for (INT I = 1; I <= messagecount; I ++) 5 {6 mail modelmail = new mail (); // Single mail entity 7 // get Single mail 8 mailmessage mailmsg = pop3.fetchmessage (I ); 9 string messageid = pop3.getmessageuniqueid (I); // unique id10 modelmail. date = mailmsg. date; // sending time 11 modelmail. subject = mailmsg. subject; // Topic 12 modelmail. body = mailmsg. htmlbody; // content 13 For (Int J = 0; j <mailmsg. to. count; j ++) // recipient 14 {15 modelmail. to + = mailmsg. to [J]. address + ";"; 16 modelmail. toname + = mailmsg. to [J]. displayname + "& lt;" + mailmsg. to [J]. address + ">"; 17} 18 for (Int J = 0; j <mailmsg. cc. count; j ++) // CC 19 {20 modelmail. CC + = mailmsg. CC [J]. address + ";"; 21 modelmail. ccname + = mailmsg. CC [J]. displayname + "& lt;" + mailmsg. CC [J]. address + ">"; 22} 23 for (Int J = 0; J <mailmsg. from. count; j ++) // sender 24 {25 modelmail. from + = mailmsg. from [J]. address + ";"; 26 modelmail. fromname + = mailmsg. from [J]. displayname + "& lt;" + mailmsg. from [J]. address + ">"; 27} 28 attachmentcollection ATT = mailmsg. attachments; // obtain the attachment 29 string Path = string. empty; 30 foreach (VAR list in ATT) 31 {32 Path = server. mappath ("/att/" + messageid + "/"); 33 If (! System. io. directory. exists (PATH) 34 {35 directory. createdirectory (PATH); 36} 37 list. save (path + list. name); 38 modelmail. ATT + = List. name + ";"; 39} 40 bytes resourcecollection maillink = mailmsg. embedded resources; // embedded attachment 41 foreach (VAR list in maillink) 42 {43 If (string. isnullorempty (list. name) 44 continue; 45 string contentid = List. contentid; 46 Path = server. mappath ("/att/" + messageid + "/"); 47 If (! System. io. directory. exists (PATH) 48 {49 directory. createdirectory (PATH); 50} 51 list. save (path + list. name); 52 modelmail. body = modelmail. body. replace ("CID:" + contentid, "/att/" + messageid + "/" + list. name); // Replace the embedded attachment 53} 54 listmail in the content. add (modelmail); 55 // Delete the original mail on the server 56 // pop3.deletemessage (I); 57} 58 // disconnect 59 pop3.disconnect ();

In fact, only so much code can be used to implement all functions. After the mail is taken, the mail on the mail server can be deleted (outlook and so on ), then you can store the data in your local database and perform a series of operations, which is almost the same as Outlook (N words are omitted). In this article, let's take a look at receiving emails and simply sending emails ,. net comes with a sender class library. If there is a next chapter, it will mention how the author sent the email, including a series of operations such as choosing the sender and attachment.

 

Well, we are looking forward to the source code, which can be downloaded here.

 

Click to download

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.