Chilkat Examples

ChilkatHOME.NET Core C#Android™AutoItCC#C++Chilkat2-PythonCkPythonClassic ASPDataFlexDelphi ActiveXDelphi DLLGoJavaLianjaMono C#Node.jsObjective-CPHP ActiveXPHP ExtensionPerlPowerBuilderPowerShellPureBasicRubySQL ServerSwift 2Swift 3,4,5...TclUnicode CUnicode C++VB.NETVBScriptVisual Basic 6.0Visual FoxProXojo Plugin

DataFlex Examples

Web API Categories

ASN.1
AWS KMS
AWS Misc
Amazon EC2
Amazon Glacier
Amazon S3
Amazon S3 (new)
Amazon SES
Amazon SNS
Amazon SQS
Async
Azure Cloud Storage
Azure Key Vault
Azure Service Bus
Azure Table Service
Base64
Bounced Email
Box
CAdES
CSR
CSV
Certificates
Code Signing
Compression
DKIM / DomainKey
DNS
DSA
Diffie-Hellman
Digital Signatures
Dropbox
Dynamics CRM
EBICS
ECC
Ed25519
Email Object
Encryption
FTP
FileAccess
Firebase
GMail REST API
GMail SMTP/IMAP/POP
Geolocation
Google APIs
Google Calendar
Google Cloud SQL
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
MS Storage Providers
Microsoft Graph
Misc
NTLM
OAuth1
OAuth2
OIDC
Office365
OneDrive
OpenSSL
Outlook
Outlook Calendar
Outlook Contact
PDF Signatures
PEM
PFX/P12
PKCS11
POP3
PRNG
REST
REST Misc
RSA
SCP
SCard
SFTP
SMTP
SSH
SSH Key
SSH Tunnel
ScMinidriver
SharePoint
SharePoint Online
Signing in the Cloud
Socket/SSL/TLS
Spider
Stream
Tar Archive
ULID/UUID
Upload
WebSocket
XAdES
XML
XML Digital Signatures
XMP
Zip
curl
uncategorized

 

 

 

(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 requires the Chilkat API to have been previously unlocked.
    // See Global Unlock Sample 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.

    // Note: A MIME sub-part can potentially be both a related item AND an attachment.
    // The typical case is when the item is contained under the multipart/related enclosure and 
    // the item also has a "Content-Disposition" header indicating "attachment".
    // The location within multipart/related makes it a "related item", yet the Content-Disposition can also make it semantically an attachment.
    // Related items and attachments are not necessarily mutually exclusive.

    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-2024 Chilkat Software, Inc. All Rights Reserved.