PowerBuilder
PowerBuilder
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 PowerBuilder Downloads
integer li_rc
integer li_Success
oleobject loo_Mailman
oleobject loo_Email
oleobject loo_BdMime
li_Success = 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).
loo_Mailman = create oleobject
li_rc = loo_Mailman.ConnectToNewObject("Chilkat.MailMan")
if li_rc < 0 then
destroy loo_Mailman
MessageBox("Error","Connecting to COM object failed")
return
end if
// Build the email to render.
loo_Email = create oleobject
li_rc = loo_Email.ConnectToNewObject("Chilkat.Email")
loo_Email.Subject = "Rendered email"
loo_Email.From = "alice@example.com"
loo_Email.AddTo("Bob","bob@example.com")
loo_Email.Body = "This message is rendered to MIME bytes in a BinData."
// Render the MIME into a BinData.
loo_BdMime = create oleobject
li_rc = loo_BdMime.ConnectToNewObject("Chilkat.BinData")
li_Success = loo_Mailman.RenderToMimeBd(loo_Email,loo_BdMime)
if li_Success = 0 then
Write-Debug loo_Mailman.LastErrorText
destroy loo_Mailman
destroy loo_Email
destroy loo_BdMime
return
end if
Write-Debug "Rendered MIME size (bytes) = " + string(loo_BdMime.NumBytes)
destroy loo_Mailman
destroy loo_Email
destroy loo_BdMime