Sample code for 30+ languages & platforms
DataFlex

Get the Value of the Nth Header Field

See more Email Object Examples

Demonstrates the Chilkat Email.GetHeaderFieldValue method, which returns the value of the Nth header field. Indexing begins at 0, and the count comes from NumHeaderFields. This example walks every header field, printing each name together with its value.

Background: GetHeaderFieldValue is the value half of index-based header enumeration — GetHeaderFieldName gives the field name at the same index. Iterating both is the reliable way to dump or inspect a full header block, including any repeated fields, which a name-based lookup would collapse to a single occurrence.

Chilkat DataFlex Downloads

DataFlex
Use ChilkatAx-win32.pkg

Procedure Test
    Handle hoEmail
    Boolean iSuccess
    Integer n
    Integer i
    String sTemp1
    String sTemp2

    //  Demonstrates the GetHeaderFieldValue method, which returns the value of the Nth header
    //  field.  Indexing begins at 0; the number of header fields is given by NumHeaderFields.

    Get Create (RefClass(cComChilkatEmail)) To hoEmail
    If (Not(IsComObjectCreated(hoEmail))) Begin
        Send CreateComObject of hoEmail
    End
    Set ComSubject Of hoEmail To "Enumerate header values"
    Set ComFrom Of hoEmail To "alice@example.com"
    Get ComAddTo Of hoEmail "Bob" "bob@example.com" To iSuccess

    Get ComNumHeaderFields Of hoEmail To n

    For i From 0 To (n - 1)
        Get ComGetHeaderFieldName Of hoEmail i To sTemp1
        Get ComGetHeaderFieldValue Of hoEmail i To sTemp2
        Showln sTemp1 " = " sTemp2
    Loop



End_Procedure