Sample code for 30+ languages & platforms
DataFlex

Save Email Attachments to Filesystem

Saves email attachments to a directory.

Chilkat DataFlex Downloads

DataFlex
Use ChilkatAx-win32.pkg

Procedure Test
    Boolean iSuccess
    Handle hoEmail
    Integer i
    String sTemp1
    Integer iTemp1

    Move False To iSuccess

    Get Create (RefClass(cComChilkatEmail)) To hoEmail
    If (Not(IsComObjectCreated(hoEmail))) Begin
        Send CreateComObject of hoEmail
    End

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

    Get ComLoadEml Of hoEmail "HtmlEmail.eml" To iSuccess
    If (iSuccess <> True) Begin
        Get ComLastErrorText Of hoEmail To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    // 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.
    Set ComOverwriteExisting Of hoEmail To True

    // 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.
    Get ComSaveAllAttachments Of hoEmail "myAttachments" To iSuccess
    If (iSuccess <> True) Begin
        Get ComLastErrorText Of hoEmail To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    // List the attachment filenames:

    Get ComNumAttachments Of hoEmail To iTemp1
    For i From 0 To (iTemp1 - 1)
        Get ComGetAttachmentFilename Of hoEmail i To sTemp1
        Showln sTemp1
    Loop



End_Procedure