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

Create, save, and reopen a plain-text email

See more Email Object Examples

Set the sender, recipient, subject, and plain-text body. Save the result as an EML file, then open it in a second Email object and read its contents.

Chilkat Perl Downloads

Perl
use strict;
use warnings;
use Chilkat2;

# Assumes Chilkat is unlocked. See Global Unlock Sample.

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

$email->Subject('Hello');
$email->Body('This is a plain-text message.');
$success = $email->SaveEml('message.eml');
if (!$success) {
    print $email->LastErrorText, "\n";
    exit;
}

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

print $received->From, "\n";
print $received->Subject, "\n";
print $received->GetPlainTextBody(), "\n";