VB.NET Examples

ChilkatHOMEASPVisual BasicVB.NETC#Visual C++CMFCDelphiFoxProJavaPerlPHPPythonRubySQL ServerVBScript

VB.NET Examples

Bounced Mail
Character Encoding
Digital Certificates
Digital Signatures
Email
FTP
HTML to XML
HTTP
IMAP
Encryption
MHT / HTML Email
PFX
RSA Encryption
S/MIME
Socket
Spider
Tar Archive
Upload
XML
XMP
Zip Compression
Misc

More Examples...
Email Object
POP3
SMTP
RSS
Atom
Self-Extractor

Byte Array
VB.NET FTPS
System.IO

Unreleased...
Service
PPMD
Deflate
Bzip2
LZW
Bz2
DH Key Exchange
DSA
Icon

 

 

 

 

 

 

Fetch Single Email by UID or Sequence Number

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

Download Chilkat .NET for 2.0 Framework

Download Chilkat .NET for 1.0 / 1.1 Framework

Dim imap As New Chilkat.Imap()

Dim success As Boolean

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


'  Connect to an IMAP server.
success = imap.Connect("mail.chilkatsoft.com")
If (success <> true) Then
    MsgBox(imap.LastErrorText)
    Exit Sub
End If


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


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



Dim email As Chilkat.Email

Dim uid As Long
uid = 2014
Dim isUid As Boolean
isUid = true

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

    '  Display the From and Subject
    TextBox1.Text = TextBox1.Text & email.FromAddress & vbCrLf
    TextBox1.Refresh()
    TextBox1.Text = TextBox1.Text & email.Subject & vbCrLf
    TextBox1.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.
    TextBox1.Text = TextBox1.Text & "---- EMAIL BODY ----" & vbCrLf
    TextBox1.Refresh()
    TextBox1.Text = TextBox1.Text & email.Body & vbCrLf
    TextBox1.Refresh()
    TextBox1.Text = TextBox1.Text & "--------------------" & vbCrLf
    TextBox1.Refresh()

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

    '  Show the total size of the email, including body and attachments:
    TextBox1.Text = TextBox1.Text & email.Size & vbCrLf
    TextBox1.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)
    TextBox1.Text = TextBox1.Text & numAttach & vbCrLf
    TextBox1.Refresh()

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

    TextBox1.Text = TextBox1.Text & "--" & vbCrLf
    TextBox1.Refresh()

End If


'  Disconnect from the IMAP server.
imap.Disconnect()
 

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

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

Mail Component · XML Parser