Sample code for 30+ languages & platforms
Unicode C

Check Whether an Email Has an HTML Body

See more Email Object Examples

Demonstrates the Chilkat Email.HasHtmlBody method, which returns true only when a text/html body is present in the current email object. This example sets an HTML body and confirms its presence.

Background: Because a message may contain a plain-text body, an HTML body, both, or neither, it is good practice to test before extracting. HasHtmlBody lets you decide whether to call GetHtmlBody or fall back to GetPlainTextBody — avoiding surprises when a sender provides only one representation.

Chilkat Unicode C Downloads

Unicode C
#include <C_CkEmailW.h>

void ChilkatSample(void)
    {
    HCkEmailW email;

    //  Demonstrates the HasHtmlBody method, which returns true only when a text/html body is
    //  present in the current email object.

    email = CkEmailW_Create();
    CkEmailW_putSubject(email,L"HasHtmlBody example");

    CkEmailW_SetHtmlBody(email,L"<html><body><b>Hello in HTML.</b></body></html>");

    if (CkEmailW_HasHtmlBody(email) == TRUE) {
        wprintf(L"The email has an HTML body.\n");
    }
    else {
        wprintf(L"The email does not have an HTML body.\n");
    }



    CkEmailW_Dispose(email);

    }