DataFlex
DataFlex
Convert a MIME Entity to multipart/alternative
See more MIME Examples
Demonstrates the Chilkat Mime.ConvertToMultipartAlt method, which wraps the current entity in a new outer multipart/alternative, making the original the first child. It takes no arguments.
Note: The file paths are relative to the application's current working directory. Absolute paths may also be used. Supply the paths appropriate to your own environment.
Background: Use this to add an alternate rendering to an existing message — for example, promoting a plain-text message so an HTML version can be added alongside it. The original content becomes the first (least-preferred) alternative, and you append the richer representation after it. As with the mixed conversion, message-level headers move to the new outer entity.
Chilkat DataFlex Downloads
Use ChilkatAx-win32.pkg
Procedure Test
Boolean iSuccess
Handle hoMime
Variant vHtmlPart
Handle hoHtmlPart
String sTemp1
Integer iTemp1
Move False To iSuccess
Get Create (RefClass(cComChilkatMime)) To hoMime
If (Not(IsComObjectCreated(hoMime))) Begin
Send CreateComObject of hoMime
End
Get ComLoadMimeFile Of hoMime "qa_data/message.eml" To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoMime To sTemp1
Showln sTemp1
Procedure_Return
End
// Wrap the current entity in a new outer multipart/alternative entity. The original entity
// becomes the first child, ready for an alternate representation to be added.
Get ComConvertToMultipartAlt Of hoMime To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoMime To sTemp1
Showln sTemp1
Procedure_Return
End
// Add an alternative representation of the same content.
Get Create (RefClass(cComChilkatMime)) To hoHtmlPart
If (Not(IsComObjectCreated(hoHtmlPart))) Begin
Send CreateComObject of hoHtmlPart
End
Get ComSetBodyFromHtml Of hoHtmlPart "<html><body>HTML alternative.</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 parts: " iTemp1
End_Procedure