Sample code for 30+ languages & platforms
PowerBuilder

Remove All Related Items from an Email

See more Email Object Examples

Demonstrates the Chilkat Email.DropRelatedItems method, which removes all related items (embedded images, style sheets, and similar resources) from the email at once. This example adds two related items and then drops them all, printing the count before and after.

Background: Related items are the inline resources bundled with an HTML body inside a multipart/related enclosure. Dropping them all in one call is handy when you want to keep the HTML text but discard its embedded media — for instance, converting a rich message to a lightweight, text-focused version, or clearing inline images before re-adding fresh ones. To remove a single item instead, use DropRelatedItem with its index.

Chilkat PowerBuilder Downloads

PowerBuilder
integer li_rc
oleobject loo_Email

//  Demonstrates the DropRelatedItems method, which removes all related items (embedded
//  images, style sheets, etc.) from the email at once.

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

//  Set an HTML body that references two related items by name (Content-Location).
loo_Email.SetHtmlBody("<html><head><link rel=~"stylesheet~" href=~"styles.css~"/></head><body><img src=~"logo.png~"/></body></html>")

//  Add two related items.
loo_Email.AddRelatedString2("styles.css","body { color: navy; }","utf-8")
loo_Email.AddRelatedString2("logo.png","(pretend image data)","utf-8")
Write-Debug "NumRelatedItems before = " + string(loo_Email.NumRelatedItems)

//  Remove all related items.
loo_Email.DropRelatedItems()

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


destroy loo_Email