Sample code for 30+ languages & platforms
PowerBuilder

Get an Email's MIME into a StringBuilder

See more Email Object Examples

Demonstrates the Chilkat Email.GetMimeSb method, which returns the email as MIME text (header, body or bodies, related items, and all attachments) by appending it to a StringBuilder object. This example builds a message and appends its MIME to a StringBuilder.

Background: This is a StringBuilder-based alternative to GetMime, which returns a plain string. Writing into a StringBuilder is more efficient when the MIME is large or when you intend to further manipulate it — searching, replacing, or accumulating additional text — without creating many intermediate string copies.

Chilkat PowerBuilder Downloads

PowerBuilder
integer li_rc
integer li_Success
oleobject loo_Email
oleobject loo_SbMime

li_Success = 0

//  Demonstrates the GetMimeSb method, which returns the email as MIME text (headers, bodies,
//  related items, and attachments), appending it to a StringBuilder object.

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 = "GetMimeSb example"
loo_Email.From = "alice@example.com"
loo_Email.AddTo("Bob","bob@example.com")
loo_Email.Body = "Hello!"

//  Append the complete MIME to a StringBuilder.
loo_SbMime = create oleobject
li_rc = loo_SbMime.ConnectToNewObject("Chilkat.StringBuilder")

li_Success = loo_Email.GetMimeSb(loo_SbMime)
if li_Success = 0 then
    Write-Debug loo_Email.LastErrorText
    destroy loo_Email
    destroy loo_SbMime
    return
end if

Write-Debug loo_SbMime.GetAsString()


destroy loo_Email
destroy loo_SbMime