Sample code for 30+ languages & platforms
PowerBuilder

Get an Email's MIME into a BinData

See more Email Object Examples

Demonstrates the Chilkat Email.GetMimeBd method, which serializes the complete RFC822/MIME message (headers, body representations, related items, and attachments) and appends the bytes to a BinData object. This example builds a message, serializes it to a BinData, and prints the byte count.

Background: A BinData holds raw bytes, which is the right container when you want the MIME as binary rather than text — for example to write it directly to a file or socket, hash it, or hand it to another API that expects a byte buffer. It is the binary counterpart to GetMime (string) and GetMimeSb (StringBuilder).

Chilkat PowerBuilder Downloads

PowerBuilder
integer li_rc
integer li_Success
oleobject loo_Email
oleobject loo_BdMime

li_Success = 0

//  Demonstrates the GetMimeBd method, which serializes the complete RFC822/MIME message
//  (headers, bodies, related items, and attachments) and appends the bytes to a BinData
//  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 = "GetMimeBd example"
loo_Email.From = "alice@example.com"
loo_Email.AddTo("Bob","bob@example.com")
loo_Email.Body = "Hello!"

//  Append the complete MIME to a BinData object.
loo_BdMime = create oleobject
li_rc = loo_BdMime.ConnectToNewObject("Chilkat.BinData")

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

Write-Debug "MIME size (bytes) = " + string(loo_BdMime.NumBytes)


destroy loo_Email
destroy loo_BdMime