AutoIt Requires Chilkat v11.0.0+
AutoIt
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 AutoIt Downloads
Local $bSuccess = False
; Assumes Chilkat is unlocked. See Global Unlock Sample.
$oOriginal = ObjCreate("Chilkat.Email")
$bSuccess = $oOriginal.LoadEml("with-attachments.eml")
If ($bSuccess <> True) Then
ConsoleWrite($oOriginal.LastErrorText & @CRLF)
Exit
EndIf
$oReply = ObjCreate("Chilkat.Email")
$bSuccess = $oOriginal.ToReply($oReply)
If ($bSuccess <> True) Then
ConsoleWrite($oOriginal.LastErrorText & @CRLF)
Exit
EndIf
$oReply.From = "Alex Rivera <alex@example.net>"
; This is a reply to the author, not a reply-all. Set the destination explicitly.
$oReply.ClearTo
$oReply.ClearCC
$oReply.ClearBcc
Local $sDestination = $oOriginal.GetHeaderField("Reply-To")
If ($sDestination = "") Then
$sDestination = $oOriginal.From
EndIf
$bSuccess = $oReply.AddMultipleTo($sDestination)
If ($bSuccess <> True) Then
ConsoleWrite($oReply.LastErrorText & @CRLF)
Exit
EndIf
; Link this answer to its parent and preserve the earlier conversation references.
Local $sParentId = $oOriginal.GetHeaderField("Message-ID")
If ($sParentId <> "") Then
$oReply.AddHeaderField "In-Reply-To",$sParentId
$oRefs = ObjCreate("Chilkat.StringBuilder")
$oRefs.Append($oOriginal.GetHeaderField("References"))
If ($oRefs.Length > 0) Then
$oRefs.Append(" ")
EndIf
$oRefs.Append($sParentId)
$oReply.AddHeaderField "References",$oRefs.GetAsString()
EndIf
; A short text reply has no use for the original inline artwork or nested correspondence.
$oReply.RemoveAttachedMessages
$oReply.RemoveHtmlAlternative
$oReply.DropRelatedItems
$oReply.SetTextBody "Thank you for your message.","text/plain"
If ($oReply.NumTo < 1) Then
ConsoleWrite("Reply has no destination. Review the original sender headers." & @CRLF)
Exit
EndIf
ConsoleWrite("Reply goes to: " & $oReply.GetToAddr(0) & @CRLF)
ConsoleWrite("In-Reply-To: " & $oReply.GetHeaderField("In-Reply-To") & @CRLF)
$bSuccess = $oReply.SaveEml("reply.eml")
If ($bSuccess <> True) Then
ConsoleWrite($oReply.LastErrorText & @CRLF)
Exit
EndIf
ConsoleWrite("Saved reply.eml." & @CRLF)