C # PO3 protocol Read message content problems

Source: Internet
Author: User

background: recently in doing a gadget to read the PO3 protocol mail server of the designated person's mail, something made up, got a while dead loop, 20 seconds to execute once,

Results run for 3 days, Monday to the IT staff to find the door, your computer what situation, how one hours to download traffic reached 1 g more, and are PO3 protocol, haha, haha

Psychology is very want to hehe, but still have to explain the situation to him truthfully, then immediately put the program stopped.

Next I was looking for a problem, and finally found the reason is because I always read the mailbox in the 180 messages, there are a lot of 180 there are a few 10 trillion attachments, haha

Solutions and causes of problems:

The problem is that this loop reads and reads content inside, because the PO3 protocol does not support reading unread messages, or marking messages as read. So I was able to iterate through all the messages and read them repeatedly,

Until there are new messages in need, deal with them and continue the loop. Then I found a way, POP3 protocol has a UID of things, each message is unique, each time gets to the mailbox all the mail uid,

Then save to local, the next time with the local and this comparison, there is a new UID in, only for the new UID for the mail read, so everything is resolved, the traffic is very small and small.

I'm using MailKit.dll here ,

Open source project, in the project with nuget dll download down, NuGet command to go to the official website to see it.

Paste out the main code:

ilist<string> msguids =client.                    Getmessageuids (); IList<string> notreaduids =Newlist<string>(); foreach(varIteminchmsguids) {                        if(!alreadysentmsgid.contains (item))                            {Notreaduids.add (item); Sw.  WriteLine (item); //record the UID of a message that has not been read                        }                    }                    if(Notreaduids.count! =0)//Read and parse if unread messages are available{IList<MimeMessage> notreadmessages =client. Getmessages (notreaduids);}

C # PO3 protocol Read message content problems encountered

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.