Sample code for 30+ languages & platforms
B4X

Remove All Attached Messages from an Email

See more Email Object Examples

Demonstrates the Chilkat Email.RemoveAttachedMessages method, which removes all message/rfc822 sub-parts (attached emails) from the object at once. Ordinary file attachments and related HTML resources are left unchanged. This example attaches two emails, removes them all, and prints the count before and after.

Background: This is the "remove them all" companion to RemoveAttachedMessage. Because it touches only the nested-message parts, you can strip forwarded originals or a digest's members while preserving the message body, its inline images, and any regular attachments — a clean way to keep the carrier message while discarding what it enclosed.

Chilkat B4X Downloads

B4X
'  Demonstrates the RemoveAttachedMessages method, which removes all message/rfc822
'  sub-parts (attached emails) from the email at once.  Ordinary file attachments and
'  related items are not affected.

Dim inner1 As ChilkatEmail
inner1.Initialize
inner1.Subject = "Embedded 1"

Dim inner2 As ChilkatEmail
inner2.Initialize
inner2.Subject = "Embedded 2"

Dim email As ChilkatEmail
email.Initialize
email.Subject = "Has attached messages"
email.AttachEmail(inner1)
email.AttachEmail(inner2)

Log("NumAttachedMessages before = " & email.NumAttachedMessages)

'  Remove all attached messages.
email.RemoveAttachedMessages

Log("NumAttachedMessages after = " & email.NumAttachedMessages)