Visual FoxPro
Visual FoxPro
Fetch Oldest/Newest IMAP Email
Emails may be downloaded by sequence number. Assuming the selected mailbox is not empty, the oldest email is at sequence number 1, and the newest email is at sequence number N. The FetchSingle method may be used to download by sequence number.Chilkat Visual FoxPro Downloads
LOCAL lnSuccess
LOCAL loImap
LOCAL n
LOCAL lnIsUid
LOCAL loOldestEmail
LOCAL loNewestEmail
lnSuccess = 0
* This example assumes the Chilkat API to have been previously unlocked.
* See Global Unlock Sample for sample code.
loImap = CreateObject('Chilkat.Imap')
* Connect to an IMAP server.
* Use TLS
loImap.Ssl = 1
loImap.Port = 993
lnSuccess = loImap.Connect("mail.testemail.net")
IF (lnSuccess = 0) THEN
? loImap.LastErrorText
RELEASE loImap
CANCEL
ENDIF
* Login
lnSuccess = loImap.Login("***","***")
IF (lnSuccess = 0) THEN
? loImap.LastErrorText
RELEASE loImap
CANCEL
ENDIF
* Select an IMAP mailbox
lnSuccess = loImap.SelectMailbox("Inbox")
IF (lnSuccess = 0) THEN
? loImap.LastErrorText
RELEASE loImap
CANCEL
ENDIF
* After selecting a mailbox, the NumMessages property
* contains the number of emails in the selected mailbox.
n = loImap.NumMessages
IF (n > 0) THEN
* The oldest email is always at sequence number 1.
lnIsUid = 0
loOldestEmail = CreateObject('Chilkat.Email')
lnSuccess = loImap.FetchEmail(0,1,lnIsUid,loOldestEmail)
IF (lnSuccess = 0) THEN
? loImap.LastErrorText
RELEASE loImap
RELEASE loOldestEmail
CANCEL
ENDIF
* Display the From and Subject
? loOldestEmail.FromAddress
? loOldestEmail.Subject
? "--"
* The newest email is at sequence number N:
loNewestEmail = CreateObject('Chilkat.Email')
lnSuccess = loImap.FetchEmail(0,n,lnIsUid,loNewestEmail)
IF (lnSuccess = 0) THEN
? loImap.LastErrorText
RELEASE loImap
RELEASE loOldestEmail
RELEASE loNewestEmail
CANCEL
ENDIF
* Display the From and Subject
? loNewestEmail.FromAddress
? loNewestEmail.Subject
ENDIF
* Disconnect from the IMAP server.
lnSuccess = loImap.Disconnect()
RELEASE loImap
RELEASE loOldestEmail
RELEASE loNewestEmail