DataFlex
DataFlex
Get the Content-Type of an Attachment
See more Email Object Examples
Demonstrates the Chilkat Email.GetAttachmentContentType method, which returns the Content-Type header field for the Nth attachment. Attachment indexing begins at 0. This example adds an attachment and reads its content type.
Background: The
Content-Type (MIME type) of an attachment — such as text/plain, application/pdf, or image/png — tells a mail client how to handle the part: whether to display it inline, offer it as a download, or pick an icon for it. Reading it lets your program filter or route attachments by type, for example extracting only the PDFs from a batch of messages.Chilkat DataFlex Downloads
Use ChilkatAx-win32.pkg
Procedure Test
Handle hoEmail
Boolean iSuccess
String sCt
// Demonstrates the GetAttachmentContentType method, which returns the Content-Type header
// field for the Nth attachment. The index is zero-based.
Get Create (RefClass(cComChilkatEmail)) To hoEmail
If (Not(IsComObjectCreated(hoEmail))) Begin
Send CreateComObject of hoEmail
End
Set ComSubject Of hoEmail To "Attachment content type"
Get ComAddStringAttachment Of hoEmail "notes.txt" "Some notes." To iSuccess
// Get the Content-Type of the first attachment (index 0).
Get ComGetAttachmentContentType Of hoEmail 0 To sCt
Showln "Attachment 0 Content-Type: " sCt
End_Procedure