Sample code for 30+ languages & platforms
PowerBuilder

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 PowerBuilder Downloads

PowerBuilder
integer li_rc
oleobject loo_Inner1
oleobject loo_Inner2
oleobject loo_Email

//  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.

loo_Inner1 = create oleobject
li_rc = loo_Inner1.ConnectToNewObject("Chilkat.Email")
if li_rc < 0 then
    destroy loo_Inner1
    MessageBox("Error","Connecting to COM object failed")
    return
end if
loo_Inner1.Subject = "Embedded 1"

loo_Inner2 = create oleobject
li_rc = loo_Inner2.ConnectToNewObject("Chilkat.Email")

loo_Inner2.Subject = "Embedded 2"

loo_Email = create oleobject
li_rc = loo_Email.ConnectToNewObject("Chilkat.Email")

loo_Email.Subject = "Has attached messages"
loo_Email.AttachEmail(loo_Inner1)
loo_Email.AttachEmail(loo_Inner2)

Write-Debug "NumAttachedMessages before = " + string(loo_Email.NumAttachedMessages)

//  Remove all attached messages.
loo_Email.RemoveAttachedMessages()

Write-Debug "NumAttachedMessages after = " + string(loo_Email.NumAttachedMessages)


destroy loo_Inner1
destroy loo_Inner2
destroy loo_Email