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

MFC 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
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

 

 

 

(MFC) 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 C/C++ Library Downloads

MS Visual C/C++ Libs

See Also: Using MFC CString in Chilkat

#include <CkMime.h>
#include <CkEmail.h>
#include <CkStringArray.h>

void ChilkatSample(void)
    {
    CkString strOut;

    // This example requires the Chilkat API to have been previously unlocked.
    // See Global Unlock Sample for sample code.

    const char *emlPath = "C:/AAWorkarea/beatrix/roesner.eml";

    CkMime mime;

    bool success = mime.LoadMimeFile(emlPath);
    if (success != true) {
        strOut.append(mime.lastErrorText());
        strOut.append("\r\n");
        SetDlgItemText(IDC_EDIT1,strOut.getUnicode());
        return;
    }

    strOut.append("---- MIME structure ----");
    strOut.append("\r\n");
    strOut.append(mime.getStructure("text"));
    strOut.append("\r\n");
    strOut.append("------------------------");
    strOut.append("\r\n");

    CkEmail email;
    success = email.LoadEml(emlPath);

    // 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.
    strOut.append("Email was Signed: ");
    strOut.appendInt(email.get_ReceivedSigned());
    strOut.append("\r\n");
    strOut.append("Email was Encrypted: ");
    strOut.appendInt(email.get_ReceivedEncrypted());
    strOut.append("\r\n");
    if (email.get_ReceivedSigned() == true) {
        strOut.append("Signature(s) valid = ");
        strOut.appendInt(email.get_SignaturesValid());
        strOut.append("\r\n");
    }

    if (email.get_ReceivedEncrypted() == true) {
        strOut.append("Decrypted successfully = ");
        strOut.appendInt(email.get_Decrypted());
        strOut.append("\r\n");
    }

    int i = 0;
    int numAttach = email.get_NumAttachments();
    strOut.append("Number of attachments = ");
    strOut.appendInt(numAttach);
    strOut.append("\r\n");

    while (i < numAttach) {
        strOut.append("---- Attachment ");
        strOut.appendInt(i);
        strOut.append("\r\n");

        // Examine the filename (if any)
        strOut.append("filename: ");
        strOut.append(email.getAttachmentFilename(i));
        strOut.append("\r\n");
        // Examine the content-ID (if any)
        strOut.append("Content-ID: ");
        strOut.append(email.getAttachmentContentID(i));
        strOut.append("\r\n");
        // Examine the content-type
        strOut.append("Content-Type: ");
        strOut.append(email.getAttachmentContentType(i));
        strOut.append("\r\n");
        // Examine the content-disposition
        strOut.append("Content-Disposition");
        strOut.append(email.getAttachmentHeader(i,"content-disposition"));
        strOut.append("\r\n");
        // Examine the attachment size:
        strOut.append("Size (in bytes) of the attachment: ");
        strOut.appendInt(email.GetAttachmentSize(i));
        strOut.append("\r\n");

        i = i + 1;
    }

    strOut.append("--");
    strOut.append("\r\n");

    // Now for the related items.
    int numRelated = email.get_NumRelatedItems();
    strOut.append("Number of related items = ");
    strOut.appendInt(numRelated);
    strOut.append("\r\n");
    i = 0;
    while (i < numRelated) {
        strOut.append("---- Related Item ");
        strOut.appendInt(i);
        strOut.append("\r\n");

        // Examine the filename (if any)
        strOut.append("filename: ");
        strOut.append(email.getRelatedFilename(i));
        strOut.append("\r\n");
        // Examine the content-ID (if any)
        strOut.append("Content-ID: ");
        strOut.append(email.getRelatedContentID(i));
        strOut.append("\r\n");
        // Examine the content-type
        strOut.append("Content-Type: ");
        strOut.append(email.getRelatedContentType(i));
        strOut.append("\r\n");
        // Examine the content-location (if any)
        strOut.append("Content-Location");
        strOut.append(email.getRelatedContentLocation(i));
        strOut.append("\r\n");

        i = i + 1;
    }

    // The email could also have attached messages.
    // An attached message is another email that was attached to this email.
    int numAttachedMessages = email.get_NumAttachedMessages();
    strOut.append("Number of attached messages = ");
    strOut.appendInt(numAttachedMessages);
    strOut.append("\r\n");
    i = 0;
    while (i < numAttachedMessages) {
        strOut.append("---- Attached message ");
        strOut.appendInt(i);
        strOut.append("\r\n");

        // Examine the attached email
        CkEmail *em = email.GetAttachedMessage(i);
        strOut.append("from: ");
        strOut.append(em->ck_from());
        strOut.append("\r\n");
        strOut.append("subject: ");
        strOut.append(em->subject());
        strOut.append("\r\n");
        delete em;
        i = i + 1;
    }

    // An email could also be a multipart/report email. 
    // This is a DSN (Delivery Status Notification)
    // The NumReports property indicates how many "reports" exist.
    int numReports = email.get_NumReports();
    i = 0;
    strOut.append("Number of reports = ");
    strOut.appendInt(numReports);
    strOut.append("\r\n");
    i = 0;
    while (i < numReports) {
        strOut.append("---- Report ");
        strOut.appendInt(i);
        strOut.append("\r\n");
        // Get the raw report data...
        strOut.append(email.getReport(i));
        strOut.append("\r\n");
        i = i + 1;
    }

    // If the email is a multipart/report, then the information
    // from the message/delivery-status part of the email can be retrieved:
    if (email.IsMultipartReport() == true) {

        strOut.append("--- Delivery Status Information:");
        strOut.append("\r\n");
        strOut.append("Status: ");
        strOut.append(email.getDeliveryStatusInfo("Status"));
        strOut.append("\r\n");
        strOut.append("Action: ");
        strOut.append(email.getDeliveryStatusInfo("Action"));
        strOut.append("\r\n");
        strOut.append("Reporting-MTA: ");
        strOut.append(email.getDeliveryStatusInfo("Reporting-MTA"));
        strOut.append("\r\n");

        CkStringArray *sa = email.GetDsnFinalRecipients();
        int numFinalRecipients = sa->get_Count();
        i = 0;
        while (i < numFinalRecipients) {
            strOut.append("final recipient: ");
            strOut.append(sa->getString(i));
            strOut.append("\r\n");
            i = i + 1;
        }

        delete sa;
    }



    SetDlgItemText(IDC_EDIT1,strOut.getUnicode());

    }

 

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