DataFlex
DataFlex
Get the Filename of an Attachment
See more Email Object Examples
Demonstrates the Chilkat Email.GetAttachmentFilename method, which retrieves an attachment's filename as stored in the MIME. The index is zero-based. This example adds an attachment and reads its filename.
Background: An attachment's filename comes from the sender's message and is not guaranteed to be safe or unique — it may include path separators or characters that are awkward on the local filesystem, and two attachments can share a name. When saving attachments to disk, treat this value as untrusted input: sanitize it and guard against collisions (see the
OverwriteExisting property, which can auto-generate unique names).Chilkat DataFlex Downloads
Use ChilkatAx-win32.pkg
Procedure Test
Handle hoEmail
Boolean iSuccess
String sFname
// Demonstrates the GetAttachmentFilename method, which retrieves an attachment's filename
// (as stored in the MIME). 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 filename"
Get ComAddStringAttachment Of hoEmail "notes.txt" "Some notes." To iSuccess
// Get the filename of the first attachment (index 0).
Get ComGetAttachmentFilename Of hoEmail 0 To sFname
Showln "Attachment 0 filename: " sFname
End_Procedure