Chilkat Examples

ChilkatHOMEAndroid™Classic ASPCC++C#Mono C#.NET Core C#C# UWP/WinRTDataFlexDelphi ActiveXDelphi DLLVisual FoxProJavaLianjaMFCObjective-CPerlPHP ActiveXPHP ExtensionPowerBuilderPowerShellPureBasicCkPythonChilkat2-PythonRubySQL ServerSwift 2Swift 3/4TclUnicode CUnicode C++Visual Basic 6.0VB.NETVB.NET UWP/WinRTVBScriptXojo PluginNode.jsExcelGo

DataFlex Examples

Web API Categories

ASN.1
Amazon Glacier
Amazon S3
Amazon S3 (new)
Amazon SES
Amazon SNS
Amazon SQS
Async
Azure Cloud Storage
Azure Service Bus
Base64
Bounced Email
Box
CAdES
CSR
CSV
Certificates
Compression
DKIM / DomainKey
DSA
Diffie-Hellman
Digital Signatures
Dropbox
Dynamics CRM
ECC
Email Object
Encryption
FTP
FileAccess
Firebase
GMail REST API
Geolocation
Google APIs
Google Calendar
Google Cloud Storage
Google Drive
Google Photos
Google Sheets
Google Tasks
Gzip
HTML-to-XML/Text

HTTP
HTTP Misc
IMAP
JSON
JSON Web Encryption (JWE)
JSON Web Signatures (JWS)
JSON Web Token (JWT)
Java KeyStore (JKS)
MHT / HTML Email
MIME
Microsoft Graph
NTLM
OAuth1
OAuth2
OneDrive
OpenSSL
Outlook
PEM
PFX/P12
POP3
PRNG
REST
REST Misc
RSA Encryption
SCP
SFTP
SMTP
SSH
SSH Key
SSH Tunnel
SharePoint
Socket/SSL/TLS
Spider
Stream
Tar Archive
Upload
WebSocket
XAdES
XML
XML Digital Signatures
XMP
Zip
curl

 

 

 

(DataFlex) Load .eml and Examine the Structure, Attachments, and Related Items

Demonstrates how to load examine the MIME structure of a .eml, and also examine the attachment and related item filenames, attached messages, and multipart/report and DSN information.

Chilkat ActiveX Downloads

ActiveX for 32-bit and 64-bit Windows

Use ChilkatAx-9.5.0-win32.pkg

Procedure Test
    String sEmlPath
    Handle hoMime
    Boolean iSuccess
    Handle hoEmail
    Integer i
    Integer iNumAttach
    Integer iNumRelated
    Integer iNumAttachedMessages
    Variant vEm
    Handle hoEm
    Integer iNumReports
    Variant vSa
    Handle hoSa
    Integer iNumFinalRecipients
    String sTemp1
    Integer iTemp1
    Boolean bTemp1

    //  This example assumes Chilkat Mime to have been previously unlocked.
    //  See Unlock Mime for sample code.

    Move "C:/AAWorkarea/beatrix/roesner.eml" To sEmlPath

    Get Create (RefClass(cComChilkatMime)) To hoMime
    If (Not(IsComObjectCreated(hoMime))) Begin
        Send CreateComObject of hoMime
    End

    Get ComLoadMimeFile Of hoMime sEmlPath To iSuccess
    If (iSuccess <> True) Begin
        Get ComLastErrorText Of hoMime To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Showln "---- MIME structure ----"
    Get ComGetStructure Of hoMime "text" To sTemp1
    Showln sTemp1
    Showln "------------------------"

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

    //  Was this a signed and/or encrypted email?
    //  If so, then loading the .eml automatically unwraps
    //  (i.e. verifies signatures and decrypts) and the resultant
    //  email is what existed prior to signing/encrypting.
    Get ComReceivedSigned Of hoEmail To bTemp1
    Showln "Email was Signed: " bTemp1
    Get ComReceivedEncrypted Of hoEmail To bTemp1
    Showln "Email was Encrypted: " bTemp1
    Get ComReceivedSigned Of hoEmail To bTemp1
    If (bTemp1 = True) Begin
        Get ComSignaturesValid Of hoEmail To bTemp1
        Showln "Signature(s) valid = " bTemp1
    End

    Get ComReceivedEncrypted Of hoEmail To bTemp1
    If (bTemp1 = True) Begin
        Get ComDecrypted Of hoEmail To bTemp1
        Showln "Decrypted successfully = " bTemp1
    End

    Move 0 To i
    Get ComNumAttachments Of hoEmail To iNumAttach
    Showln "Number of attachments = " iNumAttach

    While (i < iNumAttach)
        Showln "---- Attachment " i

        //  Examine the filename (if any)
        Get ComGetAttachmentFilename Of hoEmail i To sTemp1
        Showln "filename: " sTemp1
        //  Examine the content-ID (if any)
        Get ComGetAttachmentContentID Of hoEmail i To sTemp1
        Showln "Content-ID: " sTemp1
        //  Examine the content-type
        Get ComGetAttachmentContentType Of hoEmail i To sTemp1
        Showln "Content-Type: " sTemp1
        //  Examine the content-disposition
        Get ComGetAttachmentHeader Of hoEmail i "content-disposition" To sTemp1
        Showln "Content-Disposition" sTemp1
        //  Examine the attachment size:
        Get ComGetAttachmentSize Of hoEmail i To iTemp1
        Showln "Size (in bytes) of the attachment: " iTemp1

        Move i + 1 To i
    Loop

    Showln "--"

    //  Now for the related items.
    Get ComNumRelatedItems Of hoEmail To iNumRelated
    Showln "Number of related items = " iNumRelated
    Move 0 To i
    While (i < iNumRelated)
        Showln "---- Related Item " i

        //  Examine the filename (if any)
        Get ComGetRelatedFilename Of hoEmail i To sTemp1
        Showln "filename: " sTemp1
        //  Examine the content-ID (if any)
        Get ComGetRelatedContentID Of hoEmail i To sTemp1
        Showln "Content-ID: " sTemp1
        //  Examine the content-type
        Get ComGetRelatedContentType Of hoEmail i To sTemp1
        Showln "Content-Type: " sTemp1
        //  Examine the content-location (if any)
        Get ComGetRelatedContentLocation Of hoEmail i To sTemp1
        Showln "Content-Location" sTemp1

        Move i + 1 To i
    Loop

    //  The email could also have attached messages.
    //  An attached message is another email that was attached to this email.
    Get ComNumAttachedMessages Of hoEmail To iNumAttachedMessages
    Showln "Number of attached messages = " iNumAttachedMessages
    Move 0 To i
    While (i < iNumAttachedMessages)
        Showln "---- Attached message " i

        //  Examine the attached email
        Get ComGetAttachedMessage Of hoEmail i To vEm
        If (IsComObject(vEm)) Begin
            Get Create (RefClass(cComChilkatEmail)) To hoEm
            Set pvComObject Of hoEm To vEm
        End
        Get ComFrom Of hoEm To sTemp1
        Showln "from: " sTemp1
        Get ComSubject Of hoEm To sTemp1
        Showln "subject: " sTemp1
        Send Destroy of hoEm
        Move i + 1 To i
    Loop

    //  An email could also be a multipart/report email.
    //  This is a DSN (Delivery Status Notification)
    //  The NumReports property indicates how many "reports" exist.
    Get ComNumReports Of hoEmail To iNumReports
    Move 0 To i
    Showln "Number of reports = " iNumReports
    Move 0 To i
    While (i < iNumReports)
        Showln "---- Report " i
        //  Get the raw report data...
        Get ComGetReport Of hoEmail i To sTemp1
        Showln sTemp1
        Move i + 1 To i
    Loop

    //  If the email is a multipart/report, then the information
    //  from the message/delivery-status part of the email can be retrieved:
    Get ComIsMultipartReport Of hoEmail To bTemp1
    If (bTemp1 = True) Begin

        Showln "--- Delivery Status Information:"
        Get ComGetDeliveryStatusInfo Of hoEmail "Status" To sTemp1
        Showln "Status: " sTemp1
        Get ComGetDeliveryStatusInfo Of hoEmail "Action" To sTemp1
        Showln "Action: " sTemp1
        Get ComGetDeliveryStatusInfo Of hoEmail "Reporting-MTA" To sTemp1
        Showln "Reporting-MTA: " sTemp1

        Get ComGetDsnFinalRecipients Of hoEmail To vSa
        If (IsComObject(vSa)) Begin
            Get Create (RefClass(cComCkStringArray)) To hoSa
            Set pvComObject Of hoSa To vSa
        End
        Get ComCount Of hoSa To iNumFinalRecipients
        Move 0 To i
        While (i < iNumFinalRecipients)
            Get ComGetString Of hoSa i To sTemp1
            Showln "final recipient: " sTemp1
            Move i + 1 To i
        Loop

        Send Destroy of hoSa
    End



End_Procedure

 

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