Ricardo SIGNES > Email-Send-2.199 > Email::Send



Annotate this POD


View/Report Bugs
Module Version: 2.199   Source  


Email::Send - Simply Sending Email


Email::Send is going away... well, not really going away, but it's being officially marked "out of favor." It has API design problems that make it hard to usefully extend and rather than try to deprecate features and slowly ease in a new interface, we've released Email::Sender which fixes these problems and others. As of today, 2008-12-19, Email::Sender is young, but it's fairly well-tested. Please consider using it instead for any new work.


  use Email::Send;

  my $message = <<'__MESSAGE__';
  To: recipient@example.com
  From: sender@example.com
  Subject: Hello there folks
  How are you? Enjoy!

  $sender->mailer_args([Host => 'smtp.example.com']);
  # more complex
  my $bulk = Email::Send->new;
  for ( qw[SMTP Sendmail Qmail] ) {

  $bulk->message_modifier(sub {
      $message->header_set(To => qq[$to\@geeknest.com])


This module provides a very simple, very clean, very specific interface to multiple Email mailers. The goal of this software is to be small and simple, easy to use, and easy to extend.


      mailer      => 'NNTP',
      mailer_args => [ Host => 'nntp.example.com' ],




The mailing system you'd like to use for sending messages with this object. This is not defined by default. If you don't specify a mailer, all available plugins will be tried when the send method is called until one succeeds.


Arguments passed into the mailing system you're using.


If defined, this callback is invoked every time the send method is called on an object. The mailer object will be passed as the first argument. Second, the actual Email::Simple object for a message will be passed. Finally, any additional arguments passed to send will be passed to this method in the order they were received.

This is useful if you are sending in bulk.


  my $result = $sender->send($message, @modifier_args);

Send a message using the predetermined mailer and mailer arguments. If you have defined a message_modifier it will be called prior to sending.

The first argument you pass to send is an email message. It must be in some format that Email::Abstract can understand. If you don't have Email::Abstract installed then sending as plain text or an Email::Simple object will do.

Any remaining arguments will be passed directly into your defined message_modifier.

  my @available = $sender->all_mailers;


  # is SMTP over SSL avaialble?
    if $sender->mailer_available('SMTP', ssl => 1);

Given the name of a mailer, such as SMTP, determine if it is available. Any additional arguments passed to this method are passed directly to the is_available method of the mailer being queried.

Writing Mailers

  package Email::Send::Example;

  sub is_available {
      eval { use Net::Example }

  sub send {
      use Net::Example;

Writing new mailers is very simple. If you want to use a short name when calling send, name your mailer under the Email::Send namespace. If you don't, the full name will have to be used. A mailer only needs to implement a single function, send. It will be called from Email::Send exactly like this.

  Your::Sending::Package->send($message, @args);

$message is an Email::Simple object, @args are the extra arguments passed into Email::Send::send.


  package Email::Send::HTTP::Post;
  use strict;

  use vars qw[$AGENT $URL $FIELD];
  use Return::Value;
  sub is_available {
      eval { use LWP::UserAgent }

  sub send {
      my ($class, $message, @args);

      require LWP::UserAgent;

      if ( @args ) {
          my ($URL, $FIELD) = @args;
          $AGENT = LWP::UserAgent->new;
          unless $URL && $FIELD;
      return success;


This example will keep a UserAgent singleton unless new arguments are passed to send. It is used by calling Email::Send::send.

  $sender->mailer_args([ 'http://example.com/incoming', 'message' ]);

  $sender->send($message2); # uses saved $URL and $FIELD




This module is maintained by the Perl Email Project.



Current maintainer: Ricardo SIGNES, <rjbs@cpan.org>.

Original author: Casey West, <casey@geeknest.com>.


  Copyright (c) 2005 Casey West.  All rights reserved.
  under the same terms as Perl itself.
syntax highlighting: