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