PowerBuilder
PowerBuilder
Get an Attached Message as an Email Object
See more Email Object Examples
Demonstrates the Chilkat Email.GetAttachedEmail method, which copies the Nth embedded message/rfc822 MIME part into another Email object. The index is zero-based (valid values run from 0 through NumAttachedMessages - 1). This example attaches an email and then extracts it back into its own object.
Background: When a message forwards another email as an attachment, that nested message is a complete email in its own right.
GetAttachedEmail turns it back into a fully navigable Email object so you can read its subject, sender, body, and even its own attachments — essential for processing forwarded mail, or for tools that unpack reported spam/phishing to examine the original.Chilkat PowerBuilder Downloads
integer li_rc
integer li_Success
oleobject loo_InnerEmail
oleobject loo_Email
oleobject loo_Attached
li_Success = 0
// Demonstrates the GetAttachedEmail method, which copies the Nth embedded message/rfc822
// MIME part into another Email object. 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_InnerEmail.Body = "This is the embedded message."
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
// Copy the first embedded message (index 0) into its own Email object.
loo_Attached = create oleobject
li_rc = loo_Attached.ConnectToNewObject("Chilkat.Email")
li_Success = loo_Email.GetAttachedEmail(0,loo_Attached)
if li_Success = 0 then
Write-Debug loo_Email.LastErrorText
destroy loo_InnerEmail
destroy loo_Email
destroy loo_Attached
return
end if
Write-Debug "Attached email subject: " + loo_Attached.Subject
Write-Debug "Attached email from: " + loo_Attached.From
destroy loo_InnerEmail
destroy loo_Email
destroy loo_Attached