PowerBuilder
PowerBuilder
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 PowerBuilder Downloads
integer li_rc
oleobject loo_Email
string ls_Ct
// Demonstrates the GetAttachmentContentType method, which returns the Content-Type header
// field for the Nth attachment. The index is zero-based.
loo_Email = create oleobject
li_rc = loo_Email.ConnectToNewObject("Chilkat.Email")
if li_rc < 0 then
destroy loo_Email
MessageBox("Error","Connecting to COM object failed")
return
end if
loo_Email.Subject = "Attachment content type"
loo_Email.AddStringAttachment("notes.txt","Some notes.")
// Get the Content-Type of the first attachment (index 0).
ls_Ct = loo_Email.GetAttachmentContentType(0)
Write-Debug "Attachment 0 Content-Type: " + ls_Ct
destroy loo_Email