Sample code for 30+ languages & platforms
Xbase++

Render an Email to MIME Bytes in a BinData

See more SMTP Examples

Demonstrates the Chilkat MailMan.RenderToMimeBd method, which renders an Email object as MIME bytes and appends the result to a BinData, without sending the email. This example renders a message into a BinData and prints the byte count.

Background: This is the binary version of RenderToMime. A BinData holds raw bytes, which is the right container when you want the rendered MIME as binary — to write it directly to a file or socket, hash it, or hand it to another API expecting a byte buffer — rather than as text.

Chilkat Xbase++ Downloads

Xbase++
LOCAL nSuccess
LOCAL oMailman
LOCAL oEmail
LOCAL oBdMime

nSuccess := 0

//  Demonstrates the MailMan.RenderToMimeBd method, which renders an Email object as MIME
//  bytes and appends the result to a BinData (without sending the email).

oMailman := CreateObject("Chilkat.MailMan")

//  Build the email to render.
oEmail := CreateObject("Chilkat.Email")
oEmail:Subject := "Rendered email"
oEmail:From := "alice@example.com"
oEmail:AddTo("Bob", "bob@example.com")
oEmail:Body := "This message is rendered to MIME bytes in a BinData."

//  Render the MIME into a BinData.
oBdMime := CreateObject("Chilkat.BinData")

nSuccess := oMailman:RenderToMimeBd(oEmail, oBdMime)
IF (nSuccess == 0)
    ? oMailman:LastErrorText
    oMailman:destroy()
    oEmail:destroy()
    oBdMime:destroy()
    RETURN
ENDIF

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

oMailman:destroy()
oEmail:destroy()
oBdMime:destroy()