DataFlex
DataFlex
Add a Custom Header to an Email Attachment
See more Email Object Examples
Demonstrates the Chilkat Email.AddAttachmentHeader method, which adds a custom MIME header field to an existing attachment identified by its zero-based index. This example adds an attachment (which becomes index 0), then attaches an extra header field to it and prints the resulting MIME.
Background: In MIME, every attachment is itself a mini-message with its own small block of headers — things like
Content-Type, Content-Disposition, and Content-Transfer-Encoding that describe that specific part. AddAttachmentHeader lets you insert additional fields into that per-part header block, which is occasionally needed for interoperability with systems that look for custom X- headers or content identifiers on individual attachments.Chilkat DataFlex Downloads
Use ChilkatAx-win32.pkg
Procedure Test
Handle hoEmail
Boolean iSuccess
String sTemp1
// Demonstrates the AddAttachmentHeader method, which adds a custom MIME header field to
// an existing attachment, identified by its zero-based index.
Get Create (RefClass(cComChilkatEmail)) To hoEmail
If (Not(IsComObjectCreated(hoEmail))) Begin
Send CreateComObject of hoEmail
End
Set ComSubject Of hoEmail To "Attachment with a custom header"
Set ComBody Of hoEmail To "The attachment has an extra MIME header."
// Add an attachment; it becomes attachment index 0.
Get ComAddStringAttachment Of hoEmail "data.txt" "Attachment body." To iSuccess
// Add a custom header field to the first attachment (index 0).
Send ComAddAttachmentHeader To hoEmail 0 "X-Custom-Attachment-Header" "some value"
// The custom header now appears in the attachment's MIME part.
Get ComGetMime Of hoEmail To sTemp1
Showln sTemp1
End_Procedure