Xojo Plugin Requires Chilkat v11.0.0+
Xojo Plugin
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 Xojo Plugin Downloads
Dim success As Boolean
success = False
// Assumes Chilkat is unlocked. See Global Unlock Sample.
Dim original As New Chilkat.Email
success = original.LoadEml("with-attachments.eml")
If (success <> True) Then
System.DebugLog(original.LastErrorText)
Return
End If
Dim reply As New Chilkat.Email
success = original.ToReply(reply)
If (success <> True) Then
System.DebugLog(original.LastErrorText)
Return
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
Dim destination As String
destination = original.GetHeaderField("Reply-To")
If (destination = "") Then
destination = original.From
End If
success = reply.AddMultipleTo(destination)
If (success <> True) Then
System.DebugLog(reply.LastErrorText)
Return
End If
// Link this answer to its parent and preserve the earlier conversation references.
Dim parentId As String
parentId = original.GetHeaderField("Message-ID")
If (parentId <> "") Then
reply.AddHeaderField "In-Reply-To",parentId
Dim refs As New 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
System.DebugLog("Reply has no destination. Review the original sender headers.")
Return
End If
System.DebugLog("Reply goes to: " + reply.GetToAddr(0))
System.DebugLog("In-Reply-To: " + reply.GetHeaderField("In-Reply-To"))
success = reply.SaveEml("reply.eml")
If (success <> True) Then
System.DebugLog(reply.LastErrorText)
Return
End If
System.DebugLog("Saved reply.eml.")