VBScript Requires Chilkat v11.0.0+
VBScript
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 VBScript Downloads
Dim fso, outFile
Set fso = CreateObject("Scripting.FileSystemObject")
'Create a Unicode (utf-16) output text file.
Set outFile = fso.CreateTextFile("output.txt", True, True)
success = 0
' Assumes Chilkat is unlocked. See Global Unlock Sample.
set original = CreateObject("Chilkat.Email")
success = original.LoadEml("with-attachments.eml")
If (success <> 1) Then
outFile.WriteLine(original.LastErrorText)
WScript.Quit
End If
set reply = CreateObject("Chilkat.Email")
success = original.ToReply(reply)
If (success <> 1) Then
outFile.WriteLine(original.LastErrorText)
WScript.Quit
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
outFile.WriteLine(reply.LastErrorText)
WScript.Quit
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 = 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
outFile.WriteLine("Reply has no destination. Review the original sender headers.")
WScript.Quit
End If
outFile.WriteLine("Reply goes to: " & reply.GetToAddr(0))
outFile.WriteLine("In-Reply-To: " & reply.GetHeaderField("In-Reply-To"))
success = reply.SaveEml("reply.eml")
If (success <> 1) Then
outFile.WriteLine(reply.LastErrorText)
WScript.Quit
End If
outFile.WriteLine("Saved reply.eml.")
outFile.Close