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

Preserve the original email and save a modified copy

See more Email Object Examples

Use with-attachments.eml as a stand-in for bytes from an IMAP fetch or a message queue. Preserve those bytes first. Parse them into an Email object, add a local processing header, and serialize the result into a separate buffer. The archived input remains suitable for later byte-level inspection.

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 mimeBytes = Server.CreateObject("Chilkat.BinData")
success = mimeBytes.LoadFile("with-attachments.eml")
If (success <> 1) Then
    Response.Write "<pre>" & Server.HTMLEncode( "Failed: mimeBytes.LoadFile.") & "</pre>"
    Response.End
End If

success = mimeBytes.WriteFile("received-original.eml")
If (success <> 1) Then
    Response.Write "<pre>" & Server.HTMLEncode( "Failed: mimeBytes.WriteFile.") & "</pre>"
    Response.End
End If

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

email.AddHeaderField "X-Workflow-State","reviewed"
'  GetMimeBd appends to its destination. Use a fresh buffer for this message.
set rendered = Server.CreateObject("Chilkat.BinData")
success = email.GetMimeBd(rendered)
If (success <> 1) Then
    Response.Write "<pre>" & Server.HTMLEncode( email.LastErrorText) & "</pre>"
    Response.End
End If

success = rendered.WriteFile("reviewed.eml")
If (success <> 1) Then
    Response.Write "<pre>" & Server.HTMLEncode( "Failed: rendered.WriteFile.") & "</pre>"
    Response.End
End If

Response.Write "<pre>" & Server.HTMLEncode( "Archived received-original.eml and saved reviewed.eml.") & "</pre>"

%>
</body>
</html>