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
FileAccess
RSS
Atom
Self-Extractor
Service
PPMD
Deflate
DH Key Exchange
DSA


VB Strings
VB Byte Array

Unreleased...
Bzip2
LZW
Icon

 

 

 

 

 

 

 

Show Email Attachments

Download Chilkat XML ActiveX

Download Chilkat Zip ActiveX (includes objects for .zip, .gz, .bz2, and .Z)

Download Chilkat Email ActiveX

Demonstrates the features for accessing an email's attachments with the Chilkat Email Component. The size and filename of each attachment is available. Also, the attachment's data can be accessed in-memory without saving the attachment to disk. Methods exist to access attachment data in both string and binary form. This example shows how to load a Zip attachment directly into the Chilkat Zip component, and an XML attachment directly into the Chilkat XML component.

Private Sub ShowAttachments(email As ChilkatEmail2)

    Dim i As Integer
    Dim numAttach As Integer
    Dim numBytes As Integer
    Dim contentType As String
    Dim attachFilename As String
    Dim xmlObj As New ChilkatXml
    Dim xmlStr As String
    Dim attachData As Variant
    Dim zipObj As New ChilkatZip2
    
    numAttach = email.NumAttachments
    
    For i = 0 To numAttach - 1
    
        ' Get the Nth attachment size (in bytes)
        numBytes = email.GetAttachmentSize(i)
        
        ' Get the attachment content-type, such as "application/zip",
        ' "application/msword", "text/plain", etc.
        contentType = email.GetAttachmentContentType(i)
        
        ' Get the attachment's filename
        attachFilename = email.GetAttachmentFilename(i)
        
        ' If the attachment is a text file, we can access the attachment's
        ' contents directly.  This example checks to see if the attachment
        ' is a "text/xml" and if so, loads the XML into a ChilkatXml object.
        If (contentType = "text/xml") Then
            ' The 2nd argument to GetAttachmentString is the charset of the
            ' character data contained within the attachment.  Given that
            ' VB strings are Unicode, this allows text attachments in any
            ' character encoding to be directly accessed.
            xmlStr = email.GetAttachmentString(i, "utf-8")
            xmlObj.LoadXml xmlStr
            
            ' The GetAttachmentStringCRLF method is the same as GetAttachmentString,
            ' except that it converts all line endings to CRLF.
            xmlStr = email.GetAttachmentStringCrLf(i, "iso-8859-1")
        End If
        
        ' If the attachment contains binary data, such as with a .zip file,
        ' you may access the attachment data directly in memory via the
        ' GetAttachmentData method, which returns a Variant containing
        ' the binary data.  This example checks to see if the attachment
        ' is an application/zip, and if so, loads the Zip into a ChilkatZip2 object.
        If (contentType = "application.zip") Then
            attachData = email.GetAttachmentData(i)
            
            zipObj.OpenFromMemory attachData
            
            ' We can now access the files and data within the Zip
            ' without ever having to write the Zip to disk...
            
        End If
        
    Next
    
    
End Sub

 

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

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