Chilkat
HOME
Android™
ASP
Visual Basic
VB.NET
C#
iOS (IPhone)
Objective-C
C++
C
MFC
Delphi
FoxPro
Java
Perl
PHP Extension
PHP ActiveX
Python
PowerShell
Ruby
SQL Server
VBScript
Saving Email Attachments
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.