Sample code for 30+ languages & platforms
Classic ASP

Get an Attached Message as an Email Object

See more Email Object Examples

Demonstrates the Chilkat Email.GetAttachedEmail method, which copies the Nth embedded message/rfc822 MIME part into another Email object. The index is zero-based (valid values run from 0 through NumAttachedMessages - 1). This example attaches an email and then extracts it back into its own object.

Background: When a message forwards another email as an attachment, that nested message is a complete email in its own right. GetAttachedEmail turns it back into a fully navigable Email object so you can read its subject, sender, body, and even its own attachments — essential for processing forwarded mail, or for tools that unpack reported spam/phishing to examine the original.

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 GetAttachedEmail method, which copies the Nth embedded message/rfc822
'  MIME part into another Email object.  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"
innerEmail.Body = "This is the embedded message."

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

'  Copy the first embedded message (index 0) into its own Email object.
set attached = Server.CreateObject("Chilkat.Email")
success = email.GetAttachedEmail(0,attached)
If (success = 0) Then
    Response.Write "<pre>" & Server.HTMLEncode( email.LastErrorText) & "</pre>"
    Response.End
End If

Response.Write "<pre>" & Server.HTMLEncode( "Attached email subject: " & attached.Subject) & "</pre>"
Response.Write "<pre>" & Server.HTMLEncode( "Attached email from: " & attached.From) & "</pre>"

%>
</body>
</html>