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

Forward an email as an attachment

See more Email Object Examples

Attach the original Email to a new message as a message/rfc822 part. The recipient can open the attached email and read its original headers and body.

Chilkat AutoIt Downloads

AutoIt
Local $bSuccess = False

;  Assumes Chilkat is unlocked. See Global Unlock Sample.

$oOriginal = ObjCreate("Chilkat.Email")
$bSuccess = $oOriginal.LoadEml("message.eml")
If ($bSuccess <> True) Then
    ConsoleWrite($oOriginal.LastErrorText & @CRLF)
    Exit
EndIf

$oEmail = ObjCreate("Chilkat.Email")
$oEmail.From = "Sam Lee <sam@example.com>"
$bSuccess = $oEmail.AddTo("Alex Rivera","alex@example.net")
If ($bSuccess <> True) Then
    ConsoleWrite($oEmail.LastErrorText & @CRLF)
    Exit
EndIf

$oEmail.Subject = "Forwarded message"
$oEmail.Body = "The original email is attached."
$bSuccess = $oEmail.AttachEmail($oOriginal)
If ($bSuccess <> True) Then
    ConsoleWrite($oEmail.LastErrorText & @CRLF)
    Exit
EndIf

$bSuccess = $oEmail.SaveEml("forward-as-attachment.eml")
If ($bSuccess <> True) Then
    ConsoleWrite($oEmail.LastErrorText & @CRLF)
    Exit
EndIf

ConsoleWrite("Saved forward-as-attachment.eml." & @CRLF)