Sample code for 30+ languages & platforms
AutoIt

Attach Email as message/rfc822 sub-part to an Email

See more Email Object Examples

Demonstrates how to add attach a message/rfc822 email to another email.

Chilkat AutoIt Downloads

AutoIt
Local $bSuccess = False

;  In this example, we'll attach an email loaded from a .eml file to a new email.

Local $oEmlBytes

$oFac = ObjCreate("Chilkat.FileAccess")
$oEmlBytes = $oFac.ReadEntireFile("qa_data/eml/simple.eml")

$oEmail = ObjCreate("Chilkat.Email")
$oEmail.Subject = "This is a test email with an attached email."
$oEmail.Body = "Test with attached email."
$oEmail.AddTo("Joe","joe@example.com")
$oEmail.From = "mary@example.com"

$bSuccess = $oEmail.AttachMessage($oEmlBytes)

ConsoleWrite($oEmail.GetMime() & @CRLF)

;  ----------------------------------------------------------------------
;  Alternatively, we could do this:
$oEmailToBeAttached = ObjCreate("Chilkat.Email")
$bSuccess = $oEmailToBeAttached.LoadEml("qa_data/eml/simple.eml")

$oEmail2 = ObjCreate("Chilkat.Email")
$oEmail2.Subject = "This is a test email with an attached email."
$oEmail2.Body = "Test with attached email."
$oEmail2.AddTo("Joe","joe@example.com")
$oEmail2.From = "mary@example.com"

Local $oEmlBytes2
$oEmlBytes2 = $oEmailToBeAttached.GetMimeBinary()
$bSuccess = $oEmail2.AttachMessage($oEmlBytes2)

ConsoleWrite("----" & @CRLF)

ConsoleWrite($oEmail2.GetMime() & @CRLF)