DataFlex
DataFlex
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 DataFlex Downloads
Use ChilkatAx-win32.pkg
Procedure Test
Boolean iSuccess
Handle hoMailman
Variant vEmail
Handle hoEmail
Variant vBdMime
Handle hoBdMime
String sTemp1
Integer iTemp1
Move False To iSuccess
// Demonstrates the MailMan.RenderToMimeBd method, which renders an Email object as MIME
// bytes and appends the result to a BinData (without sending the email).
Get Create (RefClass(cComChilkatMailMan)) To hoMailman
If (Not(IsComObjectCreated(hoMailman))) Begin
Send CreateComObject of hoMailman
End
// Build the email to render.
Get Create (RefClass(cComChilkatEmail)) To hoEmail
If (Not(IsComObjectCreated(hoEmail))) Begin
Send CreateComObject of hoEmail
End
Set ComSubject Of hoEmail To "Rendered email"
Set ComFrom Of hoEmail To "alice@example.com"
Get ComAddTo Of hoEmail "Bob" "bob@example.com" To iSuccess
Set ComBody Of hoEmail To "This message is rendered to MIME bytes in a BinData."
// Render the MIME into a BinData.
Get Create (RefClass(cComChilkatBinData)) To hoBdMime
If (Not(IsComObjectCreated(hoBdMime))) Begin
Send CreateComObject of hoBdMime
End
Get pvComObject of hoEmail to vEmail
Get pvComObject of hoBdMime to vBdMime
Get ComRenderToMimeBd Of hoMailman vEmail vBdMime To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoMailman To sTemp1
Showln sTemp1
Procedure_Return
End
Get ComNumBytes Of hoBdMime To iTemp1
Showln "Rendered MIME size (bytes) = " iTemp1
End_Procedure