PowerBuilder
PowerBuilder
Create a multipart/alternative MIME Entity
See more MIME Examples
Demonstrates the Chilkat Mime.NewMultipartAlternative method, which initializes the object as an empty multipart/alternative entity. It takes no arguments; the alternative representations are then appended.
Background:
multipart/alternative holds several renderings of the same content and lets the client pick the best one it can display — the standard way to send an email as both plain text and HTML. Order matters: parts go from least to most preferred, so the plain-text version comes first and the HTML last, and a client shows the last one it understands.Chilkat PowerBuilder Downloads
integer li_rc
integer li_Success
oleobject loo_Mime
oleobject loo_TextPart
oleobject loo_HtmlPart
li_Success = 0
// Demonstrates the Mime.NewMultipartAlternative method, which initializes the object as an empty
// multipart/alternative entity, clearing any existing content. It takes no arguments.
loo_Mime = create oleobject
li_rc = loo_Mime.ConnectToNewObject("Chilkat.Mime")
if li_rc < 0 then
destroy loo_Mime
MessageBox("Error","Connecting to COM object failed")
return
end if
li_Success = loo_Mime.NewMultipartAlternative()
if li_Success = 0 then
Write-Debug loo_Mime.LastErrorText
destroy loo_Mime
return
end if
// multipart/alternative holds two representations of the SAME content; the client displays the
// last one it can render. Add a plain-text part, then an HTML part.
loo_TextPart = create oleobject
li_rc = loo_TextPart.ConnectToNewObject("Chilkat.Mime")
li_Success = loo_TextPart.SetBodyFromPlainText("Hello (plain text version).")
if li_Success = 0 then
Write-Debug loo_TextPart.LastErrorText
destroy loo_Mime
destroy loo_TextPart
return
end if
li_Success = loo_Mime.AppendPart(loo_TextPart)
if li_Success = 0 then
Write-Debug loo_Mime.LastErrorText
destroy loo_Mime
destroy loo_TextPart
return
end if
loo_HtmlPart = create oleobject
li_rc = loo_HtmlPart.ConnectToNewObject("Chilkat.Mime")
li_Success = loo_HtmlPart.SetBodyFromHtml("<html><body><b>Hello</b> (HTML version).</body></html>")
if li_Success = 0 then
Write-Debug loo_HtmlPart.LastErrorText
destroy loo_Mime
destroy loo_TextPart
destroy loo_HtmlPart
return
end if
li_Success = loo_Mime.AppendPart(loo_HtmlPart)
if li_Success = 0 then
Write-Debug loo_Mime.LastErrorText
destroy loo_Mime
destroy loo_TextPart
destroy loo_HtmlPart
return
end if
Write-Debug "Number of alternatives: " + string(loo_Mime.NumParts)
destroy loo_Mime
destroy loo_TextPart
destroy loo_HtmlPart