Sample code for 30+ languages & platforms
Classic ASP

Remove All Attached Messages from an Email

See more Email Object Examples

Demonstrates the Chilkat Email.RemoveAttachedMessages method, which removes all message/rfc822 sub-parts (attached emails) from the object at once. Ordinary file attachments and related HTML resources are left unchanged. This example attaches two emails, removes them all, and prints the count before and after.

Background: This is the "remove them all" companion to RemoveAttachedMessage. Because it touches only the nested-message parts, you can strip forwarded originals or a digest's members while preserving the message body, its inline images, and any regular attachments — a clean way to keep the carrier message while discarding what it enclosed.

Chilkat Classic ASP Downloads

Classic ASP
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<%
'  Demonstrates the RemoveAttachedMessages method, which removes all message/rfc822
'  sub-parts (attached emails) from the email at once.  Ordinary file attachments and
'  related items are not affected.

set inner1 = Server.CreateObject("Chilkat.Email")
inner1.Subject = "Embedded 1"

set inner2 = Server.CreateObject("Chilkat.Email")
inner2.Subject = "Embedded 2"

set email = Server.CreateObject("Chilkat.Email")
email.Subject = "Has attached messages"
success = email.AttachEmail(inner1)
success = email.AttachEmail(inner2)

Response.Write "<pre>" & Server.HTMLEncode( "NumAttachedMessages before = " & email.NumAttachedMessages) & "</pre>"

'  Remove all attached messages.
email.RemoveAttachedMessages 

Response.Write "<pre>" & Server.HTMLEncode( "NumAttachedMessages after = " & email.NumAttachedMessages) & "</pre>"

%>
</body>
</html>