Sample code for 30+ languages & platforms
DataFlex

Set the Content-Disposition of an Attachment

See more Email Object Examples

Demonstrates the Chilkat Email.SetAttachmentDisposition method, which sets the Content-Disposition value for the attachment at a given zero-based index. The default disposition is attachment. This example changes an attachment's disposition to inline.

Background: The Content-Disposition header hints how a client should present a part: attachment means "offer it as a download," while inline means "display it within the message" (as an email client does with an embedded image). Setting it lets you control that behavior — though clients ultimately decide how to honor the hint.

Chilkat DataFlex Downloads

DataFlex
Use ChilkatAx-win32.pkg

Procedure Test
    Boolean iSuccess
    Handle hoEmail
    String sTemp1

    Move False To iSuccess

    //  Demonstrates the SetAttachmentDisposition method, which sets the Content-Disposition
    //  value for the attachment at the given zero-based index.  The default disposition is
    //  "attachment".

    Get Create (RefClass(cComChilkatEmail)) To hoEmail
    If (Not(IsComObjectCreated(hoEmail))) Begin
        Send CreateComObject of hoEmail
    End
    Set ComSubject Of hoEmail To "Set attachment disposition"

    Get ComAddStringAttachment Of hoEmail "image.txt" "(pretend inline content)" To iSuccess

    //  Set the disposition of the first attachment (index 0) to "inline".
    Get ComSetAttachmentDisposition Of hoEmail 0 "inline" To iSuccess
    If (iSuccess = False) Begin
        Get ComLastErrorText Of hoEmail To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    //  The attachment's Content-Disposition is now "inline".
    Get ComGetMime Of hoEmail To sTemp1
    Showln sTemp1


End_Procedure