DataFlex
DataFlex
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 DataFlex Downloads
Use ChilkatAx-win32.pkg
Procedure Test
Boolean iSuccess
Handle hoMime
Variant vTextPart
Handle hoTextPart
Variant vHtmlPart
Handle hoHtmlPart
String sTemp1
Integer iTemp1
Move False To iSuccess
// Demonstrates the Mime.NewMultipartAlternative method, which initializes the object as an empty
// multipart/alternative entity, clearing any existing content. It takes no arguments.
Get Create (RefClass(cComChilkatMime)) To hoMime
If (Not(IsComObjectCreated(hoMime))) Begin
Send CreateComObject of hoMime
End
Get ComNewMultipartAlternative Of hoMime To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoMime To sTemp1
Showln sTemp1
Procedure_Return
End
// 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.
Get Create (RefClass(cComChilkatMime)) To hoTextPart
If (Not(IsComObjectCreated(hoTextPart))) Begin
Send CreateComObject of hoTextPart
End
Get ComSetBodyFromPlainText Of hoTextPart "Hello (plain text version)." To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoTextPart To sTemp1
Showln sTemp1
Procedure_Return
End
Get pvComObject of hoTextPart to vTextPart
Get ComAppendPart Of hoMime vTextPart To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoMime To sTemp1
Showln sTemp1
Procedure_Return
End
Get Create (RefClass(cComChilkatMime)) To hoHtmlPart
If (Not(IsComObjectCreated(hoHtmlPart))) Begin
Send CreateComObject of hoHtmlPart
End
Get ComSetBodyFromHtml Of hoHtmlPart "<html><body><b>Hello</b> (HTML version).</body></html>" To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoHtmlPart To sTemp1
Showln sTemp1
Procedure_Return
End
Get pvComObject of hoHtmlPart to vHtmlPart
Get ComAppendPart Of hoMime vHtmlPart To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoMime To sTemp1
Showln sTemp1
Procedure_Return
End
Get ComNumParts Of hoMime To iTemp1
Showln "Number of alternatives: " iTemp1
End_Procedure