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

 

 

 

 

 

 

 

Saving Email Attachments

Download Chilkat Email ActiveX

How to save email attachments using the Chilkat email component.

' Demonstrates how to save email attachments to a directory
Private Sub Save_Email_Attachments(dirPath As String, email As ChilkatEmail2)

    ' We can easily save all the attachments to the specified directory
    ' by calling SaveAllAttachments.
    ' The SaveAllAttachments method will automatically create the directory
    ' if it does not already exist.
    success = email.SaveAllAttachments(dirPath)
    
    ' the return value is 1 for success, 0 for failure.  A failure typically
    ' would occur if the process did not have permission to create files
    ' in the directory.
    If (success = 0) Then
        ' The last-error information should contain enough information for you
        ' to resolve the problem.
        MsgBox email.LastErrorText
        Exit Sub
    End If
    
    ' The email.OverwriteExisting property controls whether already-existing files
    ' are automatically overwritten.  By default, it is set to 1 so that existing
    ' files will be overwritten.
    
    ' Setting OverwriteExisting = 0 will cause the attachment-saving methods to generate
    ' unique filenames if a file with the same name already exists.  The actual filename(s)
    ' saved will be present by calling GetAttachmentFilename for each attachment *after*
    ' saving.
    ' For example...
    email.OverwriteExisting = 0
    success = email.SaveAllAttachments(dirPath)
    
    n = email.NumAttachments
    For i = 0 To n - 1
        ' If the attachment filename was changed to prevent overwriting,
        ' GetAttachmentFilename will return the new filename.
        List1.AddItem email.GetAttachmentFilename(i)
    Next
    
    ' You may also save individual attachments:
    For i = 0 To n - 1
        List1.AddItem "Original Filename: " & email.GetAttachmentFilename(i)
        success = email.SaveAttachedFile(i, dirPath)
        List1.AddItem "Saved Filename: " & email.GetAttachmentFilename(i)
    Next
    
End Sub

 

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