PowerBuilder
PowerBuilder
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 PowerBuilder Downloads
integer li_rc
oleobject loo_Email
// Demonstrates the RemovePlainTextAlternative method, which removes the plain-text body
// from the email (if one exists). Other body representations, attachments, and related
// items remain.
loo_Email = create oleobject
li_rc = loo_Email.ConnectToNewObject("Chilkat.Email")
if li_rc < 0 then
destroy loo_Email
MessageBox("Error","Connecting to COM object failed")
return
end if
loo_Email.Subject = "Remove plain-text alternative"
// Create an email with both plain-text and HTML alternatives.
loo_Email.SetTextBody("This is the plain-text version.","text/plain")
loo_Email.AddHtmlAlternativeBody("<html><body>This is the HTML version.</body></html>")
Write-Debug "NumAlternatives before = " + string(loo_Email.NumAlternatives)
Write-Debug "HasPlainTextBody before: " + string(loo_Email.HasPlainTextBody())
// Remove the plain-text body, leaving the HTML alternative.
loo_Email.RemovePlainTextAlternative()
Write-Debug "NumAlternatives after = " + string(loo_Email.NumAlternatives)
Write-Debug "HasPlainTextBody after: " + string(loo_Email.HasPlainTextBody())
destroy loo_Email