Sample code for 30+ languages & platforms
Visual Basic 6.0 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 Visual Basic 6.0 Downloads

Visual Basic 6.0
Dim success As Long
success = 0

'  Assumes Chilkat is unlocked. See Global Unlock Sample.

Dim original As New ChilkatEmail
success = original.LoadEml("with-attachments.eml")
If (success <> 1) Then
    Debug.Print original.LastErrorText
    Exit Sub
End If

Dim reply As New ChilkatEmail
success = original.ToReply(reply)
If (success <> 1) Then
    Debug.Print original.LastErrorText
    Exit Sub
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 <> 1) Then
    Debug.Print reply.LastErrorText
    Exit Sub
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 ChilkatStringBuilder
    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
    Debug.Print "Reply has no destination. Review the original sender headers."
    Exit Sub
End If

Debug.Print "Reply goes to: " & reply.GetToAddr(0)
Debug.Print "In-Reply-To: " & reply.GetHeaderField("In-Reply-To")

success = reply.SaveEml("reply.eml")
If (success <> 1) Then
    Debug.Print reply.LastErrorText
    Exit Sub
End If

Debug.Print "Saved reply.eml."