Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

rjbs (4671)

  (email not shown publicly)
AOL IM: RicardoJBSignes (Add Buddy, Send Message)
Yahoo! ID: RicardoSignes (Add User, Send Message)

I'm a Perl coder living in Bethlehem, PA and working Philadelphia. I'm a philosopher and theologan by training, but I was shocked to learn upon my graduation that these skills don't have many associated careers. Now I write code.

Journal of rjbs (4671)

Saturday July 14, 2007
03:52 PM

finally, a simple e-mail module

[ #33806 ]

Email::Simple is, I think, a pretty popular module. Quite a few other Perl software distributions require it or its subclass Email::MIME. I think its popularity is due in no small part to the very simple interface it provides. There's no need to remember that sometimes you need the "bodyhandle" method and that sometimes you need "open." There's no need to keep track of encodings or parts or much of anything. It's just a header and a body and that's about it.

Now and then, I've made Email::Simple do a little more or a little less. I'd like to address the "how big should it be?" question, but until I have a definitive answer, I know what I have to expect: complaints. "Why can't it read an mbox??" and "Why would you want to be able to NOT fold headers??" and so on.

I have produced a simpler interface for e-mail, which I think will be the least thing people are likely to ask for. The beauty of it is, there are no methods. It's just data! Lots of Perl programmers are wary of objects, but they all love to make hashes of things. This just takes that a step further:

$e_mail->{From} = '"Ricardo Signes" <rjbs(my initials)>';
$e_mail->{To  } = '';
$e_mail->{Subject} = "Re: (no subject)";

@$e_mail = "No, I think that's a great idea."
          , "I'll see you there.\n\n"
          , "> Would it be stupid to go crash PyCon this weekend?"
          , "> I have Monday off, so we can get totally plastered."

There's your e-mail, constructed in a nice, Perlish style. You can, of course, assign more than one at once:

$e_mail->{Bcc} = [ '', '' ];

You can always fix up your headers, later, too:

# Prune secret internal headers.
my $rcvd = $e_mail->{Received};
for (reverse 0 .. $#$rcvd) {
  delete $rcvd->[ $_ ] if $rcvd->[ $_ ] =~ /\.internal /;


One of Email::Simple's big weaknesses is that it lacks support for multipart mail. Email::MIME supports it, but has a bunch of prerequisites. My new offering requires only core modules, but does offer multipart mail support:

$e_mail = ( ... set up top-level e-mail ... );
$attach = ( ... set up attachment ...);

push @$e_mail, $attach;


Well, not quote done, right? The purpose of an email is to be sent. Email::Simple is hardly useful on its own, because it can't send mail. Email::Send is confusing, has prerequisites, and means you're stuck dealing with more objects!

Our email structure can be sent easily with no external modules:


Or, if you don't have sendmail in your path:


It's already available on the CPAN.

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.
  • Intrigued, I read the source code for your new email module.


    For a second there I wanted to write Email::Tiny.

    Just for a second though, and then I got over it, because I'd much prefer to pay for the dependencies for Email::Stuff [] :)
  • You have an error in your example code. The assignment to @$e_mail needs parentheses around the array elements. Otherwise, @$e_mail just gets the first one and the rest fall into void context.
  • I use MIME::Lite for doing email stuff. How does that compare?
    • I'd sooner use E'Mail::Acme than MIME::Lite.

      Of course, I'd sooner use steel wool to brush my teeth than use MIME::Lite.