Sample code for 30+ languages & platforms
C++ Requires Chilkat v11.0.0+

Read the timestamp from the most recent Received header

See more Email Object Examples

Read the topmost Received field of a delivered message. Its timestamp follows the final semicolon. A draft can have no trace header, and some relays supply an unparseable timestamp.

Chilkat C++ Downloads

C++
#include <CkEmail.h>
#include <CkStringBuilder.h>
#include <CkDateTime.h>

void ChilkatSample(void)
    {
    bool success = false;

    //  Assumes Chilkat is unlocked. See Global Unlock Sample.

    CkEmail email;
    success = email.LoadEml("received.eml");
    if (success != true) {
        std::cout << email.lastErrorText() << "\r\n";
        return;
    }

    CkStringBuilder trace;
    trace.Append(email.getHeaderField("Received"));
    if (trace.Contains(";",true) != true) {
        std::cout << "No timestamp delimiter in the top Received field." << "\r\n";
        return;
    }

    const char *stamp = trace.getAfterFinal(";",false);
    trace.SetString(stamp);
    trace.Trim();
    std::cout << "Relay timestamp: " << trace.getAsString() << "\r\n";
    CkDateTime when;
    success = when.SetFromRfc822(trace.getAsString());
    if (success != true) {
        std::cout << "Failed: when.SetFromRfc822." << "\r\n";
        return;
    }

    std::cout << "UTC: " << when.getAsTimestamp(false) << "\r\n";
    }