Visual Basic Examples

ChilkatHOMEASPVisual BasicVB.NETC#Visual C++CMFCDelphiFoxProJavaPerlPHPPythonRubySQL ServerVBScript

VB Examples

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

More Examples...
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 Single Email by UID or Sequence Number

Download Chilkat IMAP ActiveX

Assuming the UID is known, download a single email by UID from an IMAP mail server.

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.chilkatsoft.com")
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

Dim email As ChilkatEmail2

Dim uid As Long
uid = 2014
Dim isUid As Long
isUid = 1

Set email = imap.FetchSingle(uid,isUid)
If (Not (email Is Nothing )) Then

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

    '  Display the Body property, which is the default body.
    '  If an email has an HTML body, the Body property contains
    '  the HTML source.  Otherwise it contains the plain-text
    '  body.
    Text1.Text = Text1.Text & "---- EMAIL BODY ----" & vbCrLf
    Text1.Refresh
    Text1.Text = Text1.Text & email.Body & vbCrLf
    Text1.Refresh
    Text1.Text = Text1.Text & "--------------------" & vbCrLf
    Text1.Refresh

    '  Display the recipients:
    Dim j As Long
    For j = 0 To email.NumTo - 1
        Text1.Text = Text1.Text & email.GetToName(j) _
             & ", " & email.GetToAddr(j) & vbCrLf
        Text1.Refresh
    Next
    For j = 0 To email.NumCC - 1
        Text1.Text = Text1.Text & email.GetCcName(j) _
             & ", " & email.GetCcAddr(j) & vbCrLf
        Text1.Refresh
    Next

    '  Show the total size of the email, including body and attachments:
    Text1.Text = Text1.Text & email.Size & vbCrLf
    Text1.Refresh

    '  When a full email is downloaded, we would use the
    '  email.NumAttachments property in conjunction with the
    '  email.GetMailAttach* methods.
    '  However, when an email object contains only the header,
    '  we need to access the attachment info differently:
    Dim numAttach As Long
    numAttach = imap.GetMailNumAttach(email)
    Text1.Text = Text1.Text & numAttach & vbCrLf
    Text1.Refresh

    For j = 0 To numAttach - 1
        Text1.Text = Text1.Text & imap.GetMailAttachFilename(email,j) & vbCrLf
        Text1.Refresh
        Dim attachSize As Long
        attachSize = imap.GetMailAttachSize(email,j)
        Text1.Text = Text1.Text & "    size = " _
             & attachSize & " bytes" & vbCrLf
        Text1.Refresh
    Next

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

End If

'  Disconnect from the IMAP server.
imap.Disconnect 

Need a specific example? Send a request to support@chilkatsoft.com

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