Sample code for 30+ languages & platforms
Lianja

Save Email Attachments to Filesystem

Saves email attachments to a directory.

Chilkat Lianja Downloads

Lianja
llSuccess = .F.

loEmail = createobject("CkEmail")

//  Load an email object containing attachments.
//  This .eml can be downloaded from:
//  http://www.example-code.com/testData/HtmlEmail.eml

llSuccess = loEmail.LoadEml("HtmlEmail.eml")
if (llSuccess <> .T.) then
    ? loEmail.LastErrorText
    release loEmail
    return
endif

//  If OverwriteExisting is turned on, files with the same
//  name are overwritten.  If turned off, new/unique filenames
//  are automatically generated.  The filenames actually saved
//  are accessible via the GetAttachmentFilename method.
loEmail.OverwriteExisting = .T.

//  Save all attachments to the "myAttachments" subdirectory
//  found under the calling process's current working directory.
//  This directory is automatically created if it does not already
//  exist.
llSuccess = loEmail.SaveAllAttachments("myAttachments")
if (llSuccess <> .T.) then
    ? loEmail.LastErrorText
    release loEmail
    return
endif

//  List the attachment filenames:

for i = 0 to loEmail.NumAttachments - 1
    ? loEmail.GetAttachmentFilename(i)
next


release loEmail