Sample code for 30+ languages & platforms
PowerBuilder

Embed a Message as message/rfc822

See more MIME Examples

Demonstrates the Chilkat Mime.NewMessageRfc822 method, which clears the object and initializes it as a message/rfc822 entity whose body is a serialized copy of another Mime. The only argument is the message to embed.

Background: message/rfc822 wraps a whole email as the body of another — the mechanism behind forwarding a message "as attachment" or bundling one message inside another. The inner message is copied at the time of the call, so later edits to the source do not change the embedded copy. The result is a self-contained part a mail client will present as a nested message.

Chilkat PowerBuilder Downloads

PowerBuilder
integer li_rc
integer li_Success
oleobject loo_InnerMsg
oleobject loo_Mime

li_Success = 0

//  Demonstrates the Mime.NewMessageRfc822 method, which clears the current object and initializes
//  it as a message/rfc822 entity whose body is a serialized copy of another Mime.  The only
//  argument is the Mime to embed.

//  Build the inner message to embed.
loo_InnerMsg = create oleobject
li_rc = loo_InnerMsg.ConnectToNewObject("Chilkat.Mime")
if li_rc < 0 then
    destroy loo_InnerMsg
    MessageBox("Error","Connecting to COM object failed")
    return
end if
li_Success = loo_InnerMsg.SetHeaderField("Subject","Forwarded message")
if li_Success = 0 then
    Write-Debug loo_InnerMsg.LastErrorText
    destroy loo_InnerMsg
    return
end if

li_Success = loo_InnerMsg.SetBodyFromPlainText("This is the original message being forwarded.")
if li_Success = 0 then
    Write-Debug loo_InnerMsg.LastErrorText
    destroy loo_InnerMsg
    return
end if

//  Wrap it as message/rfc822 (an embedded/forwarded email).
loo_Mime = create oleobject
li_rc = loo_Mime.ConnectToNewObject("Chilkat.Mime")

li_Success = loo_Mime.NewMessageRfc822(loo_InnerMsg)
if li_Success = 0 then
    Write-Debug loo_Mime.LastErrorText
    destroy loo_InnerMsg
    destroy loo_Mime
    return
end if

Write-Debug "Content-Type: " + loo_Mime.ContentType


destroy loo_InnerMsg
destroy loo_Mime