DataFlex
DataFlex
Remove a Single Attached Message from an Email
See more Email Object Examples
Demonstrates the Chilkat Email.RemoveAttachedMessage method, which removes the Nth message/rfc822 sub-part (an attached email) from the message. Indexing begins at 0. This example attaches an email, removes it, and prints the attached-message count before and after.
Background: Attached messages (forwarded emails carried as
message/rfc822 parts) are counted and indexed separately from ordinary file attachments and related items. RemoveAttachedMessage targets just one nested email by index — useful, for example, when trimming a bundled digest or stripping a forwarded original before re-sending.Chilkat DataFlex Downloads
Use ChilkatAx-win32.pkg
Procedure Test
Boolean iSuccess
Variant vInnerEmail
Handle hoInnerEmail
Handle hoEmail
String sTemp1
Integer iTemp1
Move False To iSuccess
// Demonstrates the RemoveAttachedMessage method, which removes the Nth message/rfc822
// sub-part (attached email) of the email. The index is zero-based.
// Build an inner email and attach it to an outer email.
Get Create (RefClass(cComChilkatEmail)) To hoInnerEmail
If (Not(IsComObjectCreated(hoInnerEmail))) Begin
Send CreateComObject of hoInnerEmail
End
Set ComSubject Of hoInnerEmail To "Embedded message"
Set ComFrom Of hoInnerEmail To "alice@example.com"
Get Create (RefClass(cComChilkatEmail)) To hoEmail
If (Not(IsComObjectCreated(hoEmail))) Begin
Send CreateComObject of hoEmail
End
Set ComSubject Of hoEmail To "Has an attached message"
Get pvComObject of hoInnerEmail to vInnerEmail
Get ComAttachEmail Of hoEmail vInnerEmail To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoEmail To sTemp1
Showln sTemp1
Procedure_Return
End
Get ComNumAttachedMessages Of hoEmail To iTemp1
Showln "NumAttachedMessages before = " iTemp1
// Remove the first attached message (index 0).
Send ComRemoveAttachedMessage To hoEmail 0
Get ComNumAttachedMessages Of hoEmail To iTemp1
Showln "NumAttachedMessages after = " iTemp1
End_Procedure