Classic ASP
Classic ASP
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 Classic ASP Downloads
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<%
' Demonstrates the RemovePlainTextAlternative method, which removes the plain-text body
' from the email (if one exists). Other body representations, attachments, and related
' items remain.
set email = Server.CreateObject("Chilkat.Email")
email.Subject = "Remove plain-text alternative"
' Create an email with both plain-text and HTML alternatives.
email.SetTextBody "This is the plain-text version.","text/plain"
success = email.AddHtmlAlternativeBody("<html><body>This is the HTML version.</body></html>")
Response.Write "<pre>" & Server.HTMLEncode( "NumAlternatives before = " & email.NumAlternatives) & "</pre>"
Response.Write "<pre>" & Server.HTMLEncode( "HasPlainTextBody before: " & email.HasPlainTextBody()) & "</pre>"
' Remove the plain-text body, leaving the HTML alternative.
email.RemovePlainTextAlternative
Response.Write "<pre>" & Server.HTMLEncode( "NumAlternatives after = " & email.NumAlternatives) & "</pre>"
Response.Write "<pre>" & Server.HTMLEncode( "HasPlainTextBody after: " & email.HasPlainTextBody()) & "</pre>"
%>
</body>
</html>