DataFlex
DataFlex
Remove the Plain-Text Body from an Email
See more Email Object Examples
Demonstrates the Chilkat Email.RemovePlainTextAlternative method, which removes the plain-text body from the email if one exists. Other body representations, attachments, and related items remain unchanged. This example builds a message with both plain-text and HTML alternatives, then removes the plain text.
Background: This is the counterpart to
RemoveHtmlAlternative. Removing the plain-text alternative leaves an HTML-only message. Note that dropping the plain-text fallback is generally discouraged for real mail — it hurts accessibility and can raise spam scores — but it is occasionally needed when a downstream system expects a single HTML representation.Chilkat DataFlex Downloads
Use ChilkatAx-win32.pkg
Procedure Test
Handle hoEmail
Boolean iSuccess
Integer iTemp1
Boolean bTemp1
// Demonstrates the RemovePlainTextAlternative method, which removes the plain-text body
// from the email (if one exists). Other body representations, attachments, and related
// items remain.
Get Create (RefClass(cComChilkatEmail)) To hoEmail
If (Not(IsComObjectCreated(hoEmail))) Begin
Send CreateComObject of hoEmail
End
Set ComSubject Of hoEmail To "Remove plain-text alternative"
// Create an email with both plain-text and HTML alternatives.
Send ComSetTextBody To hoEmail "This is the plain-text version." "text/plain"
Get ComAddHtmlAlternativeBody Of hoEmail "<html><body>This is the HTML version.</body></html>" To iSuccess
Get ComNumAlternatives Of hoEmail To iTemp1
Showln "NumAlternatives before = " iTemp1
Get ComHasPlainTextBody Of hoEmail To bTemp1
Showln "HasPlainTextBody before: " bTemp1
// Remove the plain-text body, leaving the HTML alternative.
Send ComRemovePlainTextAlternative To hoEmail
Get ComNumAlternatives Of hoEmail To iTemp1
Showln "NumAlternatives after = " iTemp1
Get ComHasPlainTextBody Of hoEmail To bTemp1
Showln "HasPlainTextBody after: " bTemp1
End_Procedure