Sample code for 30+ languages & platforms
PowerBuilder

Remove All Attachments from an Email

See more Email Object Examples

Demonstrates the Chilkat Email.DropAttachments method, which removes all ordinary attachments from the in-memory message. Related items (inline images, style sheets) and attached message/rfc822 emails are not affected. This example adds two attachments, drops them, and prints the count before and after.

Background: Chilkat distinguishes three kinds of enclosed content: ordinary attachments (files meant to be saved), related items (resources that support the HTML display), and nested attached messages. DropAttachments targets only the first category — useful, for example, when forwarding or re-sending a message body without carrying its original file attachments along.

Chilkat PowerBuilder Downloads

PowerBuilder
integer li_rc
oleobject loo_Email

//  Demonstrates the DropAttachments method, which removes all ordinary attachments from
//  the email.  Related items and attached messages are not affected.

loo_Email = create oleobject
li_rc = loo_Email.ConnectToNewObject("Chilkat.Email")
if li_rc < 0 then
    destroy loo_Email
    MessageBox("Error","Connecting to COM object failed")
    return
end if
loo_Email.Subject = "Drop attachments example"

loo_Email.AddStringAttachment("a.txt","first attachment")
loo_Email.AddStringAttachment("b.txt","second attachment")
Write-Debug "NumAttachments before = " + string(loo_Email.NumAttachments)

//  Remove all attachments.
loo_Email.DropAttachments()

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


destroy loo_Email