Visual Basic Examples

ChilkatHOMEAndroid™ASPVisual BasicVB.NETC#iOS (IPhone)Objective-CC++CMFCDelphiFoxProJavaPerl
PHP ExtensionPHP ActiveXPythonPowerShellRubySQL ServerVBScript

VB Examples

Bounced Mail
Bz2
Character Encoding
CSV
Digital Certificates
Digital Signatures
Email
FTP
HTML Conversion
HTTP
IMAP
Encryption
MHT / HTML Email
POP3
RSA
S/MIME
SFTP
SMTP
Socket
Spider
SSH
SSH Key
SSH Tunnel
String
Tar
Upload
XML
XMP
Zip Compression

More Examples...
Amazon S3
Email Object
DKIM / DomainKey
NTLM
DH Key Exchange
DSA
FileAccess
RSS
Atom
Self-Extractor
Service
Bzip2
PPMD
Deflate
LZW


VB Strings
VB Byte Array

 

 

 

 

 

 

 

Fetch Oldest/Newest IMAP Email

Download Chilkat Email ActiveX

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.

Download 32-bit Chilkat IMAP ActiveX (.msi)

Download All 32-bit Chilkat ActiveX Components (.zip)

Download All 64-bit Chilkat ActiveX Components (.zip)

Dim imap As New ChilkatImap

Dim success As Long

'  Anything unlocks the component and begins a fully-functional 30-day trial.
success = imap.UnlockComponent("Anything for 30-day trial")
If (success <> 1) Then
    MsgBox imap.LastErrorText
    Exit Sub
End If

'  Connect to an IMAP server.
success = imap.Connect("mail.testemail.net")
If (success <> 1) Then
    MsgBox imap.LastErrorText
    Exit Sub
End If

'  Login
success = imap.Login("***","***")
If (success <> 1) Then
    MsgBox imap.LastErrorText
    Exit Sub
End If

'  Select an IMAP mailbox
success = imap.SelectMailbox("Inbox")
If (success <> 1) Then
    MsgBox imap.LastErrorText
    Exit Sub
End If

'  After selecting a mailbox, the NumMessages property
'  contains the number of emails in the selected mailbox.
Dim n As Long
n = imap.NumMessages

If (n > 0) Then

    '  The oldest email is always at sequence number 1.
    Dim isUid As Long
    isUid = 0

    Dim oldestEmail As ChilkatEmail2
    Set oldestEmail = imap.FetchSingle(1,isUid)
    If (Not (oldestEmail Is Nothing )) Then

        '  Display the From and Subject
        Text1.Text = Text1.Text & oldestEmail.FromAddress & vbCrLf
        Text1.Text = Text1.Text & oldestEmail.Subject & vbCrLf

        Text1.Text = Text1.Text & "--" & vbCrLf

    End If

    '  The newest email is at sequence number N:
    Dim newestEmail As ChilkatEmail2
    Set newestEmail = imap.FetchSingle(n,isUid)
    If (Not (newestEmail Is Nothing )) Then

        '  Display the From and Subject
        Text1.Text = Text1.Text & newestEmail.FromAddress & vbCrLf
        Text1.Text = Text1.Text & newestEmail.Subject & vbCrLf

    End If

End If

'  Disconnect from the IMAP server.
imap.Disconnect 

© 2000-2012 Chilkat Software, Inc. All Rights Reserved.