VBScript Examples

ChilkatHOMEASPVisual BasicVB.NETC#Visual C++CMFCDelphiFoxProJavaPerlPHPPythonRubySQL ServerVBScript

VBScript 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
String
Tar
Upload
XML
XMP
Zip Compression
Self-Extractor

More Examples...
Email Object
POP3
SMTP
Byte Array
RSS
Atom

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 IMAP ActiveX

Dim fso, outFile
Set fso = CreateObject("Scripting.FileSystemObject")
Set outFile = fso.CreateTextFile("output.txt", True)

set imap = CreateObject("Chilkat.Imap")

'  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
    WScript.Quit
End If

'  Connect to an IMAP server.
success = imap.Connect("mail.chilkatsoft.com")
If (success <> 1) Then
    MsgBox imap.LastErrorText
    WScript.Quit
End If

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

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

uid = 2014
isUid = 1

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

    '  Display the From and Subject
    outFile.WriteLine(email.FromAddress)
    outFile.WriteLine(email.Subject)

    '  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.
    outFile.WriteLine("---- EMAIL BODY ----")
    outFile.WriteLine(email.Body)
    outFile.WriteLine("--------------------")

    '  Display the recipients:

    For j = 0 To email.NumTo - 1
        outFile.WriteLine(email.GetToName(j) _
             & ", " & email.GetToAddr(j))
    Next
    For j = 0 To email.NumCC - 1
        outFile.WriteLine(email.GetCcName(j) _
             & ", " & email.GetCcAddr(j))
    Next

    '  Show the total size of the email, including body and attachments:
    outFile.WriteLine(email.Size)

    '  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:
    numAttach = imap.GetMailNumAttach(email)
    outFile.WriteLine(numAttach)

    For j = 0 To numAttach - 1
        outFile.WriteLine(imap.GetMailAttachFilename(email,j))
        attachSize = imap.GetMailAttachSize(email,j)
        outFile.WriteLine("    size = " & attachSize _
             & " bytes")
    Next

    outFile.WriteLine("--")

End If

'  Disconnect from the IMAP server.
imap.Disconnect 
outFile.Close

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

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

Mail Component · XML Parser