.\" -*- mode: troff; coding: utf-8 -*- .\" Automatically generated by Pod::Man 5.01 (Pod::Simple 3.43) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>. .ie n \{\ . ds C` "" . ds C' "" 'br\} .el\{\ . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "Email::Send 3" .TH Email::Send 3 2023-07-25 "perl v5.38.0" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH NAME Email::Send \- Simply Sending Email .SH "WAIT! ACHTUNG!" .IX Header "WAIT! ACHTUNG!" 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::Send\fBer\fR 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. .SH SYNOPSIS .IX Header "SYNOPSIS" .Vb 1 \& use Email::Send; \& \& my $message = <<\*(Aq_\|_MESSAGE_\|_\*(Aq; \& To: recipient@example.com \& From: sender@example.com \& Subject: Hello there folks \& \& How are you? Enjoy! \& _\|_MESSAGE_\|_ \& \& my $sender = Email::Send\->new({mailer => \*(AqSMTP\*(Aq}); \& $sender\->mailer_args([Host => \*(Aqsmtp.example.com\*(Aq]); \& $sender\->send($message); \& \& # more complex \& my $bulk = Email::Send\->new; \& for ( qw[SMTP Sendmail Qmail] ) { \& $bulk\->mailer($_) and last if $bulk\->mailer_available($_); \& } \& \& $bulk\->message_modifier(sub { \& my ($sender, $message, $to) = @_; \& $message\->header_set(To => qq[$to\e@geeknest.com]) \& }); \& \& my @to = qw[casey chastity evelina casey_jr marshall]; \& my $rv = $bulk\->send($message, $_) for @to; .Ve .SH DESCRIPTION .IX Header "DESCRIPTION" 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. .SS Constructors .IX Subsection "Constructors" .IP new 4 .IX Item "new" .Vb 4 \& my $sender = Email::Send\->new({ \& mailer => \*(AqNNTP\*(Aq, \& mailer_args => [ Host => \*(Aqnntp.example.com\*(Aq ], \& }); .Ve .Sp Create a new mailer object. This method can take parameters for any of the data properties of this module. Those data properties, which have their own accessors, are listed under "Properties". .SS Properties .IX Subsection "Properties" .IP mailer 4 .IX Item "mailer" 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 \f(CW\*(C`send\*(C'\fR method is called until one succeeds. .IP mailer_args 4 .IX Item "mailer_args" Arguments passed into the mailing system you're using. .IP message_modifier 4 .IX Item "message_modifier" If defined, this callback is invoked every time the \f(CW\*(C`send\*(C'\fR method is called on an object. The mailer object will be passed as the first argument. Second, the actual \f(CW\*(C`Email::Simple\*(C'\fR object for a message will be passed. Finally, any additional arguments passed to \f(CW\*(C`send\*(C'\fR will be passed to this method in the order they were received. .Sp This is useful if you are sending in bulk. .SS METHODS .IX Subsection "METHODS" .IP send 4 .IX Item "send" .Vb 1 \& my $result = $sender\->send($message, @modifier_args); .Ve .Sp Send a message using the predetermined mailer and mailer arguments. If you have defined a \f(CW\*(C`message_modifier\*(C'\fR it will be called prior to sending. .Sp The first argument you pass to send is an email message. It must be in some format that \f(CW\*(C`Email::Abstract\*(C'\fR can understand. If you don't have \&\f(CW\*(C`Email::Abstract\*(C'\fR installed then sending as plain text or an \f(CW\*(C`Email::Simple\*(C'\fR object will do. .Sp Any remaining arguments will be passed directly into your defined \&\f(CW\*(C`message_modifier\*(C'\fR. .IP all_mailers 4 .IX Item "all_mailers" .Vb 1 \& my @available = $sender\->all_mailers; .Ve .Sp Returns a list of available mailers. These are mailers that are installed on your computer and register themselves as available. .IP mailer_available 4 .IX Item "mailer_available" .Vb 3 \& # is SMTP over SSL avaialble? \& $sender\->mailer(\*(AqSMTP\*(Aq) \& if $sender\->mailer_available(\*(AqSMTP\*(Aq, ssl => 1); .Ve .Sp Given the name of a mailer, such as \f(CW\*(C`SMTP\*(C'\fR, determine if it is available. Any additional arguments passed to this method are passed directly to the \f(CW\*(C`is_available\*(C'\fR method of the mailer being queried. .SS "Writing Mailers" .IX Subsection "Writing Mailers" .Vb 1 \& package Email::Send::Example; \& \& sub is_available { \& eval { use Net::Example } \& } \& \& sub send { \& my ($class, $message, @args) = @_; \& use Net::Example; \& Net::Example\->do_it($message) or return; \& } \& \& 1; .Ve .PP Writing new mailers is very simple. If you want to use a short name when calling \f(CW\*(C`send\*(C'\fR, name your mailer under the \f(CW\*(C`Email::Send\*(C'\fR namespace. If you don't, the full name will have to be used. A mailer only needs to implement a single function, \f(CW\*(C`send\*(C'\fR. It will be called from \&\f(CW\*(C`Email::Send\*(C'\fR exactly like this. .PP .Vb 1 \& Your::Sending::Package\->send($message, @args); .Ve .PP \&\f(CW$message\fR is an Email::Simple object, \f(CW@args\fR are the extra arguments passed into \f(CW\*(C`Email::Send::send\*(C'\fR. .PP Here's an example of a mailer that sends email to a URL. .PP .Vb 2 \& 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; \& } \& return failure "Can\*(Aqt send to URL if no URL and field are named" \& unless $URL && $FIELD; \& $AGENT\->post($URL => { $FIELD => $message\->as_string }); \& return success; \& } \& \& 1; .Ve .PP This example will keep a UserAgent singleton unless new arguments are passed to \f(CW\*(C`send\*(C'\fR. It is used by calling \f(CW\*(C`Email::Send::send\*(C'\fR. .PP .Vb 1 \& my $sender = Email::Send\->new({ mailer => \*(AqHTTP::Post\*(Aq }); \& \& $sender\->mailer_args([ \*(Aqhttp://example.com/incoming\*(Aq, \*(Aqmessage\*(Aq ]); \& \& $sender\->send($message); \& $sender\->send($message2); # uses saved $URL and $FIELD .Ve .SH "SEE ALSO" .IX Header "SEE ALSO" Email::Simple, Email::Abstract, Email::Send::IO, Email::Send::NNTP, Email::Send::Qmail, Email::Send::SMTP, Email::Send::Sendmail, perl. .SH "PERL EMAIL PROJECT" .IX Header "PERL EMAIL PROJECT" This module is maintained by the Perl Email Project. .PP .SH AUTHOR .IX Header "AUTHOR" Current maintainer: Ricardo SIGNES, <\fIrjbs@cpan.org\fR>. .PP Original author: Casey West, <\fIcasey@geeknest.com\fR>. .SH COPYRIGHT .IX Header "COPYRIGHT" .Vb 3 \& Copyright (c) 2005 Casey West. All rights reserved. \& This module is free software; you can redistribute it and/or modify it \& under the same terms as Perl itself. .Ve