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

Perl
use strict;
use warnings;
use Chilkat2;

# Assumes Chilkat is unlocked. See Global Unlock Sample.

my $original = Chilkat2::Email->new;
my $success = $original->LoadEml('message.eml');
if (!$success) {
    print $original->LastErrorText, "\n";
    exit;
}

my $email = Chilkat2::Email->new;
$email->From('Sam Lee <sam@example.com>');
$success = $email->AddTo('Alex Rivera', 'alex@example.net');
if (!$success) {
    print $email->LastErrorText, "\n";
    exit;
}

$email->Subject('Forwarded message');
$email->Body('The original email is attached.');
$success = $email->AttachEmail($original);
if (!$success) {
    print $email->LastErrorText, "\n";
    exit;
}

$success = $email->SaveEml('forward-as-attachment.eml');
if (!$success) {
    print $email->LastErrorText, "\n";
    exit;
}

print "Saved forward-as-attachment.eml.\n";