Skip to content

Instantly share code, notes, and snippets.

@jkeenan
Last active December 3, 2017 19:14
Show Gist options
  • Save jkeenan/22e16ca0b608d9fff043070b4944e658 to your computer and use it in GitHub Desktop.
Save jkeenan/22e16ca0b608d9fff043070b4944e658 to your computer and use it in GitHub Desktop.
Send an email on a system where 'sendmail' is running
#!/usr/bin/env perl
use strict;
use warnings;
use 5.12.0;
use Email::Sender::Simple qw(sendmail);
use Email::Simple;
use Email::Simple::Creator;
my $instructions =
'http://search.cpan.org/~rjbs/Email-Sender-1.300031/lib/Email/Sender/Manual/QuickStart.pm';
my $body = <<EOF;
This message is short, but at least it's cheap.
It's adapted directly from $instructions.
EOF
my $email = Email::Simple->create(
header => [
To => q|"James E Keenan" <jkeenan@pobox.com>|,
# Don't try to send me mail at thenceforward.net; use pobox.com address
From => q|"Jim Keenan's Linode" <jkeenan@thenceforward.net>|,
Subject => q|Email via Email::Simple and Email::Sender::Simple|,
],
body => $body,
);
{
local $@;
eval {
sendmail($email);
};
if ($@) { say "Problem: <$@>"; }
else { say "Finished"; }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment