Sample code for 30+ languages & platforms
Visual FoxPro

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 Visual FoxPro Downloads

Visual FoxPro
LOCAL lnSuccess
LOCAL loMailman
LOCAL loEmail
LOCAL loBdMime

lnSuccess = 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).

loMailman = CreateObject('Chilkat.MailMan')

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

*  Render the MIME into a BinData.
loBdMime = CreateObject('Chilkat.BinData')

lnSuccess = loMailman.RenderToMimeBd(loEmail,loBdMime)
IF (lnSuccess = 0) THEN
    ? loMailman.LastErrorText
    RELEASE loMailman
    RELEASE loEmail
    RELEASE loBdMime
    CANCEL
ENDIF

? "Rendered MIME size (bytes) = " + STR(loBdMime.NumBytes)

RELEASE loMailman
RELEASE loEmail
RELEASE loBdMime