Sample code for 30+ languages & platforms
Xbase++

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 Xbase++ Downloads

Xbase++
LOCAL nSuccess
LOCAL oEmail
LOCAL oBdMime

nSuccess := 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.

oEmail := CreateObject("Chilkat.Email")
oEmail:Subject := "GetMimeBd example"
oEmail:From := "alice@example.com"
oEmail:AddTo("Bob", "bob@example.com")
oEmail:Body := "Hello!"

//  Append the complete MIME to a BinData object.
oBdMime := CreateObject("Chilkat.BinData")
nSuccess := oEmail:GetMimeBd(oBdMime)
IF (nSuccess == 0)
    ? oEmail:LastErrorText
    oEmail:destroy()
    oBdMime:destroy()
    RETURN
ENDIF

? "MIME size (bytes) = " + Str(oBdMime:NumBytes)

oEmail:destroy()
oBdMime:destroy()