Sample code for 30+ languages & platforms
Classic ASP

Remove a Single Attached Message from an Email

See more Email Object Examples

Demonstrates the Chilkat Email.RemoveAttachedMessage method, which removes the Nth message/rfc822 sub-part (an attached email) from the message. Indexing begins at 0. This example attaches an email, removes it, and prints the attached-message count before and after.

Background: Attached messages (forwarded emails carried as message/rfc822 parts) are counted and indexed separately from ordinary file attachments and related items. RemoveAttachedMessage targets just one nested email by index — useful, for example, when trimming a bundled digest or stripping a forwarded original before re-sending.

Chilkat Classic ASP Downloads

Classic ASP
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<%
success = 0

'  Demonstrates the RemoveAttachedMessage method, which removes the Nth message/rfc822
'  sub-part (attached email) of the email.  The index is zero-based.

'  Build an inner email and attach it to an outer email.
set innerEmail = Server.CreateObject("Chilkat.Email")
innerEmail.Subject = "Embedded message"
innerEmail.From = "alice@example.com"

set email = Server.CreateObject("Chilkat.Email")
email.Subject = "Has an attached message"
success = email.AttachEmail(innerEmail)
If (success = 0) Then
    Response.Write "<pre>" & Server.HTMLEncode( email.LastErrorText) & "</pre>"
    Response.End
End If

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

'  Remove the first attached message (index 0).
email.RemoveAttachedMessage 0

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

%>
</body>
</html>