Basically, you have to construct a "multipart/mixed" email message with a "message/rfc822" part that holds the email you want to enclose.
inner_msg=$(cat - <<END_MSG
To: santa.clause@northpole.example.com
From: virginia@doubtful.invalid
Subject: do you exist
I am doubtful
Regards,
V.
END_MSG
)
Then you can build the message to send:
boundary="this is the boundary: $$-$(date +%s)"
msg=$(cat - << END_MSG
To: recipient@example.com
From: sender@example.com
Subject: I contain a message
Content-Type: multipart/mixed; boundary="$boundary"
Mime-Version: 1.0
This is a multipart message in MIME format.
--$boundary
Content-Type: text/plain; charset=ISO-8859-1
This is the body of the 'container' message.
The email attachment follows.
--$boundary
Content-Type message/rfc822
Content-Disposition: attachment; filename="attached_email.eml"
$inner_msg
--$boundary--
END_MSG
)
You can now send "$msg"
using whatever mechanism you choose:
echo "$msg" | sendmail -oi -t
(this is untested and may be buggy)