Sample code for 30+ languages & platforms
Unicode C

Get a Header Field by Name

See more Email Object Examples

Demonstrates the Chilkat Email.GetHeaderField method, which returns the value of a header field by name. Header-field names are case-insensitive, so X-Priority and x-priority refer to the same field. This example reads several headers by name.

Background: Looking up a header by name is the quickest way to read a known field like Subject or a custom X- header. One caveat: some header names (such as Received) can legitimately appear more than once. When a field may repeat and you need every occurrence, enumerate by index with GetHeaderFieldName and GetHeaderFieldValue instead of looking up by name.

Chilkat Unicode C Downloads

Unicode C
#include <C_CkEmailW.h>

void ChilkatSample(void)
    {
    HCkEmailW email;

    //  Demonstrates the GetHeaderField method, which returns the value of a header field by
    //  name.  Header-field names are case-insensitive.

    email = CkEmailW_Create();
    CkEmailW_putSubject(email,L"Quarterly report");
    CkEmailW_putFrom(email,L"alice@example.com");
    CkEmailW_AddHeaderField(email,L"X-Priority",L"1");

    //  Get header field values by name.
    wprintf(L"Subject = %s\n",CkEmailW_getHeaderField(email,L"Subject"));
    wprintf(L"From = %s\n",CkEmailW_getHeaderField(email,L"From"));
    wprintf(L"X-Priority = %s\n",CkEmailW_getHeaderField(email,L"x-priority"));


    CkEmailW_Dispose(email);

    }