Chilkat HOME ASP Visual Basic VB.NET C# Visual C++ Delphi FoxPro Java Perl Python Ruby SQL Server VBScript
|
POP3: Download Most Recent Email (method 1)How to ready the N most recent email from a POP3 server. The POP3 protocol does not provide the ability to request the most recent email, nor does it provide the ability to download email based on read/unread status or any other criteria. The design principle behind POP3 is that it is a temporary holding store for incoming email and email clients or other applications will transfer email from the POP3 server to a local persistent store where it will be managed. Therefore, POP3 does not provide sophisticated functionality (as opposed to IMAP which has the opposite design philosophy: that email is maintained and organized on the server). This example shows one possible way to retrieve the N most recent emails from a POP3 server. It downloads the headers into a bundle object, then sorts the bundle by date, and finally retrieves the most recent emails by UIDL. Another alternative is to download the UIDL list and then assume that the 1st N UIDLs are the most recent.
LOCAL loMailman LOCAL lnSuccess LOCAL loBundle LOCAL lnAscending LOCAL loSaUidls LOCAL i LOCAL n LOCAL loEmail LOCAL loBundle2 * The mailman object is used for receiving (POP3) * and sending (SMTP) email. loMailman = CreateObject('Chilkat.MailMan2') * Any string argument automatically begins the 30-day trial. lnSuccess = loMailman.UnlockComponent("30-day trial") IF (lnSuccess <> 1) THEN =MESSAGEBOX("Component unlock failed") QUIT ENDIF * Set the POP3 server's hostname loMailman.MailHost = "mail.chilkatsoft.com" * Set the POP3 login/password. loMailman.PopUsername = "admin@chilkatsoft.com" loMailman.PopPassword = "*myPassword5*" * Read mail headers and one line of the body. loBundle = loMailman.GetAllHeaders(1) IF (loBundle = NULL ) THEN =MESSAGEBOX(loMailman.LastErrorText) QUIT ENDIF * Sort the bundle by date lnAscending = 0 loBundle.SortByDate(lnAscending) * Get the 10 most recent UIDLs loSaUidls = CreateObject('Chilkat.CkStringArray') n = loBundle.MessageCount IF (n > 10) THEN n = 10 ENDIF FOR i = 0 TO n - 1 loEmail = loBundle.GetEmail(i) loSaUidls.Append(loEmail.Uidl) RELEASE loEmail NEXT RELEASE loBundle * Download in full the 10 most recent emails: loBundle2 = loMailman.FetchMultiple(loSaUidls) IF (loBundle2 = NULL ) THEN =MESSAGEBOX(loMailman.LastErrorText) QUIT ENDIF FOR i = 0 TO loBundle2.MessageCount - 1 loEmail = loBundle2.GetEmail(i) ? loEmail.From ? loEmail.Subject ? "----" RELEASE loEmail NEXT |
Need a specific example? Send a request to support@chilkatsoft.com
© 2000-2007 Chilkat Software, Inc. All Rights Reserved.
Mail Component · .NET Email Component · ASP Mail Component · XML Parser