Classic ASP
Classic ASP
Clear an Email Object
See more Email Object Examples
Demonstrates the Chilkat Email.Clear method, which removes the current message content — recipients, headers, body representations, attachments, related items, and embedded messages — leaving an empty email object. This example builds a message with a recipient and attachment, clears it, and prints the counts before and after.
Background: Reusing a single
Email object across many operations is efficient, but leftover state from a previous message could leak into the next. Clear resets the object completely, giving you a clean slate — the safe way to start a fresh message without allocating a new object.Chilkat Classic ASP Downloads
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<%
' Demonstrates the Clear method, which removes the current message content, including
' recipients, headers, body representations, attachments, related items, and embedded
' messages -- leaving an empty email object.
set email = Server.CreateObject("Chilkat.Email")
email.Subject = "A message"
email.Body = "Some body text."
success = email.AddTo("Bob","bob@example.com")
success = email.AddStringAttachment("notes.txt","Some notes.")
Response.Write "<pre>" & Server.HTMLEncode( "NumTo before clear = " & email.NumTo) & "</pre>"
Response.Write "<pre>" & Server.HTMLEncode( "NumAttachments before clear = " & email.NumAttachments) & "</pre>"
' Remove all content, resetting the email object.
email.Clear
Response.Write "<pre>" & Server.HTMLEncode( "NumTo after clear = " & email.NumTo) & "</pre>"
Response.Write "<pre>" & Server.HTMLEncode( "NumAttachments after clear = " & email.NumAttachments) & "</pre>"
%>
</body>
</html>