PureBasic
PureBasic
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 PureBasic Downloads
IncludeFile "CkBinData.pb"
IncludeFile "CkEmail.pb"
IncludeFile "CkMailMan.pb"
Procedure ChilkatExample()
success.i = 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).
mailman.i = CkMailMan::ckCreate()
If mailman.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
; Build the email to render.
email.i = CkEmail::ckCreate()
If email.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
CkEmail::setCkSubject(email, "Rendered email")
CkEmail::setCkFrom(email, "alice@example.com")
CkEmail::ckAddTo(email,"Bob","bob@example.com")
CkEmail::setCkBody(email, "This message is rendered to MIME bytes in a BinData.")
; Render the MIME into a BinData.
bdMime.i = CkBinData::ckCreate()
If bdMime.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
success = CkMailMan::ckRenderToMimeBd(mailman,email,bdMime)
If success = 0
Debug CkMailMan::ckLastErrorText(mailman)
CkMailMan::ckDispose(mailman)
CkEmail::ckDispose(email)
CkBinData::ckDispose(bdMime)
ProcedureReturn
EndIf
Debug "Rendered MIME size (bytes) = " + Str(CkBinData::ckNumBytes(bdMime))
CkMailMan::ckDispose(mailman)
CkEmail::ckDispose(email)
CkBinData::ckDispose(bdMime)
ProcedureReturn
EndProcedure