Sample code for 30+ languages & platforms
Classic ASP Requires Chilkat v11.0.0+

Reply to an email and preserve its thread

See more Email Object Examples

Create a reply to with-attachments.eml. Address it to Reply-To when supplied, or to the original author otherwise. Link the reply to the original Message-ID, replace its body with a short answer, and print the destination before saving the draft.

Chilkat Classic ASP Downloads

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

'  Assumes Chilkat is unlocked. See Global Unlock Sample.

set original = Server.CreateObject("Chilkat.Email")
success = original.LoadEml("with-attachments.eml")
If (success <> 1) Then
    Response.Write "<pre>" & Server.HTMLEncode( original.LastErrorText) & "</pre>"
    Response.End
End If

set reply = Server.CreateObject("Chilkat.Email")
success = original.ToReply(reply)
If (success <> 1) Then
    Response.Write "<pre>" & Server.HTMLEncode( original.LastErrorText) & "</pre>"
    Response.End
End If

reply.From = "Alex Rivera <alex@example.net>"
'  This is a reply to the author, not a reply-all. Set the destination explicitly.
reply.ClearTo 
reply.ClearCC 
reply.ClearBcc 
destination = original.GetHeaderField("Reply-To")
If (destination = "") Then
    destination = original.From
End If

success = reply.AddMultipleTo(destination)
If (success <> 1) Then
    Response.Write "<pre>" & Server.HTMLEncode( reply.LastErrorText) & "</pre>"
    Response.End
End If

'  Link this answer to its parent and preserve the earlier conversation references.
parentId = original.GetHeaderField("Message-ID")
If (parentId <> "") Then
    reply.AddHeaderField "In-Reply-To",parentId
    set refs = Server.CreateObject("Chilkat.StringBuilder")
    success = refs.Append(original.GetHeaderField("References"))
    If (refs.Length > 0) Then
        success = refs.Append(" ")
    End If

    success = refs.Append(parentId)
    reply.AddHeaderField "References",refs.GetAsString()
End If

'  A short text reply has no use for the original inline artwork or nested correspondence.
reply.RemoveAttachedMessages 
reply.RemoveHtmlAlternative 
reply.DropRelatedItems 
reply.SetTextBody "Thank you for your message.","text/plain"
If (reply.NumTo < 1) Then
    Response.Write "<pre>" & Server.HTMLEncode( "Reply has no destination. Review the original sender headers.") & "</pre>"
    Response.End
End If

Response.Write "<pre>" & Server.HTMLEncode( "Reply goes to: " & reply.GetToAddr(0)) & "</pre>"
Response.Write "<pre>" & Server.HTMLEncode( "In-Reply-To: " & reply.GetHeaderField("In-Reply-To")) & "</pre>"

success = reply.SaveEml("reply.eml")
If (success <> 1) Then
    Response.Write "<pre>" & Server.HTMLEncode( reply.LastErrorText) & "</pre>"
    Response.End
End If

Response.Write "<pre>" & Server.HTMLEncode( "Saved reply.eml.") & "</pre>"

%>
</body>
</html>