Sample code for 30+ languages & platforms
PowerBuilder

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

PowerBuilder
integer li_rc
integer li_Success
oleobject loo_InnerEmail
oleobject loo_Email

li_Success = 0

//  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.
loo_InnerEmail = create oleobject
li_rc = loo_InnerEmail.ConnectToNewObject("Chilkat.Email")
if li_rc < 0 then
    destroy loo_InnerEmail
    MessageBox("Error","Connecting to COM object failed")
    return
end if
loo_InnerEmail.Subject = "Embedded message"
loo_InnerEmail.From = "alice@example.com"

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

loo_Email.Subject = "Has an attached message"
li_Success = loo_Email.AttachEmail(loo_InnerEmail)
if li_Success = 0 then
    Write-Debug loo_Email.LastErrorText
    destroy loo_InnerEmail
    destroy loo_Email
    return
end if

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

//  Remove the first attached message (index 0).
loo_Email.RemoveAttachedMessage(0)

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


destroy loo_InnerEmail
destroy loo_Email