Sample code for 30+ languages & platforms
PureBasic

Get the Content-Type of a Related Item

See more Email Object Examples

Demonstrates the Chilkat Email.GetRelatedContentType method, which returns the Content-Type of the Nth related content item in an email. The index is zero-based. This example adds a related style sheet and reads its content type.

Background: Each related item declares a Content-Typeimage/png for an inline image, text/css for a style sheet, and so on — that tells the rendering client how to use it. Reading the content type lets a program enumerate a message's embedded resources and act on them by kind, for example collecting every inline image while ignoring the style sheets.

Chilkat PureBasic Downloads

PureBasic
IncludeFile "CkEmail.pb"

Procedure ChilkatExample()

    ;  Demonstrates the GetRelatedContentType method, which returns the Content-Type of the Nth
    ;  related content item in an email.  The index is zero-based.

    email.i = CkEmail::ckCreate()
    If email.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    CkEmail::setCkSubject(email, "GetRelatedContentType example")

    ;  The HTML references the style sheet by name (Content-Location).
    CkEmail::ckSetHtmlBody(email,"<html><head><link rel=" + Chr(34) + "stylesheet" + Chr(34) + " href=" + Chr(34) + "styles.css" + Chr(34) + "/></head><body>Styled.</body></html>")

    ;  Add the related style sheet (index 0).
    CkEmail::ckAddRelatedString2(email,"styles.css","body { color: navy; }","utf-8")

    ;  Read the Content-Type of the first related item (index 0).
    ct.s = CkEmail::ckGetRelatedContentType(email,0)
    Debug "Related item 0 Content-Type: " + ct


    CkEmail::ckDispose(email)


    ProcedureReturn
EndProcedure