.\" -*- 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::Stuffer 3pm" .TH Email::Stuffer 3pm 2024-03-05 "perl v5.38.2" "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::Stuffer \- A more casual approach to creating and sending Email:: emails .SH VERSION .IX Header "VERSION" version 0.020 .SH SYNOPSIS .IX Header "SYNOPSIS" .Vb 3 \& # Prepare the message \& my $body = <<\*(AqAMBUSH_READY\*(Aq; \& Dear Santa \& \& I have killed Bun Bun. \& \& Yes, I know what you are thinking... but it was actually a total accident. \& \& I was in a crowded line at a BayWatch signing, and I tripped, and stood on \& his head. \& \& I know. Oops! :/ \& \& So anyways, I am willing to sell you the body for $1 million dollars. \& \& Be near the pinhole to the Dimension of Pain at midnight. \& \& Alias \& \& AMBUSH_READY \& \& # Create and send the email in one shot \& Email::Stuffer\->from (\*(Aqcpan@ali.as\*(Aq ) \& \->to (\*(Aqsanta@northpole.org\*(Aq ) \& \->bcc (\*(Aqbunbun@sluggy.com\*(Aq ) \& \->text_body($body ) \& \->attach_file(\*(Aqdead_bunbun_faked.gif\*(Aq ) \& \->send; .Ve .SH DESCRIPTION .IX Header "DESCRIPTION" \&\fBThe basics should all work, but this module is still subject to name and/or API changes\fR .PP Email::Stuffer, as its name suggests, is a fairly casual module used to stuff things into an email and send them. It is a high-level module designed for ease of use when doing a very specific common task, but implemented on top of the light and tolerable Email:: modules. .PP Email::Stuffer is typically used to build emails and send them in a single statement, as seen in the synopsis. And it is certain only for use when creating and sending emails. As such, it contains no email parsing capability, and little to no modification support. .PP To re-iterate, this is very much a module for those "slap it together and fire it off" situations, but that still has enough grunt behind the scenes to do things properly. .SS "Default Transport" .IX Subsection "Default Transport" Although it cannot be relied upon to work, the default behaviour is to use \f(CW\*(C`sendmail\*(C'\fR to send mail, if you don't provide the mail send channel with either the \f(CW\*(C`transport\*(C'\fR method, or as an argument to \f(CW\*(C`send\*(C'\fR. .PP (Actually, the choice of default is delegated to Email::Sender::Simple, which makes its own choices. But usually, it uses \f(CW\*(C`sendmail\*(C'\fR.) .SS "Why use this?" .IX Subsection "Why use this?" Why not just use Email::Simple or Email::MIME? After all, this just adds another layer of stuff around those. Wouldn't using them directly be better? .PP Certainly, if you know EXACTLY what you are doing. The docs are clear enough, but you really do need to have an understanding of the structure of MIME emails. This structure is going to be different depending on whether you have text body, HTML, both, with or without an attachment etc. .PP Then there's brevity... compare the following roughly equivalent code. .PP First, the Email::Stuffer way. .PP .Vb 5 \& Email::Stuffer\->to(\*(AqSimon Cozens\*(Aq) \& \->from(\*(AqSanta@northpole.org\*(Aq) \& \->text_body("You\*(Aqve been good this year. No coal for you.") \& \->attach_file(\*(Aqchoochoo.gif\*(Aq) \& \->send; .Ve .PP And now doing it directly with a knowledge of what your attachment is, and what the correct MIME structure is. .PP .Vb 3 \& use Email::MIME; \& use Email::Sender::Simple; \& use IO::All; \& \& Email::Sender::Simple\->try_to_send( \& Email::MIME\->create( \& header => [ \& To => \*(Aqsimon@somewhere.jp\*(Aq, \& From => \*(Aqsanta@northpole.org\*(Aq, \& ], \& parts => [ \& Email::MIME\->create( \& body => "You\*(Aqve been a good boy this year. No coal for you." \& ), \& Email::MIME\->create( \& body => io(\*(Aqchoochoo.gif\*(Aq), \& attributes => { \& filename => \*(Aqchoochoo.gif\*(Aq, \& content_type => \*(Aqimage/gif\*(Aq, \& }, \& ), \& ], \& ); \& ); .Ve .PP Again, if you know MIME well, and have the patience to manually code up the Email::MIME structure, go do that, if you really want to. .PP Email::Stuffer as the name suggests, solves one case and one case only: generate some stuff, and email it to somewhere, as conveniently as possible. DWIM, but do it as thinly as possible and use the solid Email:: modules underneath. .SH "PERL VERSION" .IX Header "PERL VERSION" This library should run on perls released even a long time ago. It should work on any version of perl released in the last five years. .PP Although it may work on older versions of perl, no guarantee is made that the minimum required version will not be increased. The version may be increased for any reason, and there is no promise that patches will be accepted to lower the minimum required perl. .SH METHODS .IX Header "METHODS" As you can see from the synopsis, all methods that \fBmodify\fR the Email::Stuffer object returns the object, and thus most normal calls are chainable. .PP However, please note that \f(CW\*(C`send\*(C'\fR, and the group of methods that do not change the Email::Stuffer object \fBdo not\fR return the object, and thus \&\fBare not\fR chainable. .SS new .IX Subsection "new" Creates a new, empty, Email::Stuffer object. .PP You can pass a hashref of properties to set, including: .IP \(bu 4 to .IP \(bu 4 from .IP \(bu 4 cc .IP \(bu 4 bcc .IP \(bu 4 reply_to .IP \(bu 4 subject .IP \(bu 4 text_body .IP \(bu 4 html_body .IP \(bu 4 transport .PP The to, cc, bcc, and reply_to headers properties may be provided as array references. The array's contents will be used as the list of arguments to the setter. .SS header_names .IX Subsection "header_names" Returns, as a list, all of the headers currently set for the Email For backwards compatibility, this method can also be called as B[headers]. .SS parts .IX Subsection "parts" Returns, as a list, the Email::MIME parts for the Email .SS header .IX Subsection "header" .Vb 1 \& $stuffer\->header($header_name = $value) .Ve .PP This method sets a named header in the email. Multiple calls with the same \&\f(CW$header_name\fR will overwrite previous calls \f(CW$value\fR. .SS to .IX Subsection "to" .Vb 1 \& $stuffer\->to(@addresses) .Ve .PP This method sets the To header in the email. .SS from .IX Subsection "from" .Vb 1 \& $stuffer\->from($address) .Ve .PP This method sets the From header in the email. .SS reply_to .IX Subsection "reply_to" .Vb 1 \& $stuffer\->reply_to($address) .Ve .PP This method sets the Reply-To header in the email. .SS cc .IX Subsection "cc" .Vb 1 \& $stuffer\->cc(@addresses) .Ve .PP This method sets the Cc header in the email. .SS bcc .IX Subsection "bcc" .Vb 1 \& $stuffer\->bcc(@addresses) .Ve .PP This method sets the Bcc header in the email. .SS subject .IX Subsection "subject" .Vb 1 \& $stuffer\->subject($text) .Ve .PP This method sets the Subject header in the email. .SS text_body .IX Subsection "text_body" .Vb 1 \& $stuffer\->text_body($body, %attributes); .Ve .PP Sets the text body of the email. Appropriate headers are set for you. You may override MIME attributes as needed. See the \f(CW\*(C`attributes\*(C'\fR parameter to "create" in Email::MIME for the headers you can set. .PP If \f(CW$body\fR is undefined, this method will do nothing. .PP Prior to Email::Stuffer version 0.015 text body was marked as flowed, which broke all pre-formated body text. Empty space at the beggining of the line was dropped and every new line character could be changed to one space (and vice versa). Version 0.015 (and later) does not set flowed format automatically anymore and so text body is really plain text. If you want to use old behavior of "advanced" flowed formatting, set flowed format manually by: \f(CW\*(C`text_body($body, format => \*(Aqflowed\*(Aq)\*(C'\fR. .SS html_body .IX Subsection "html_body" .Vb 1 \& $stuffer\->html_body($body, %attributes); .Ve .PP Sets the HTML body of the email. Appropriate headers are set for you. You may override MIME attributes as needed. See the \f(CW\*(C`attributes\*(C'\fR parameter to "create" in Email::MIME for the headers you can set. .PP If \f(CW$body\fR is undefined, this method will do nothing. .SS attach .IX Subsection "attach" .Vb 1 \& $stuffer\->attach($contents, %attributes) .Ve .PP Adds an attachment to the email. The first argument is the file contents followed by (as for text_body and html_body) the list of headers to use. Email::Stuffer will \fItry\fR to guess the headers correctly, but you may wish to provide them anyway to be sure. Encoding is Base64 by default. See the \f(CW\*(C`attributes\*(C'\fR parameter to "create" in Email::MIME for the headers you can set. .SS attach_file .IX Subsection "attach_file" .Vb 1 \& $stuffer\->attach_file($file, %attributes) .Ve .PP Attachs a file that already exists on the filesystem to the email. \&\f(CW\*(C`attach_file\*(C'\fR will attempt to auto-detect the MIME type, and use the file's current name when attaching. See the \f(CW\*(C`attributes\*(C'\fR parameter to "create" in Email::MIME for the headers you can set. .PP \&\f(CW$file\fR can be a filename or an IO::All::File object. .SS transport .IX Subsection "transport" .Vb 1 \& $stuffer\->transport( $moniker, @options ) .Ve .PP or .PP .Vb 1 \& $stuffer\->transport( $transport_obj ) .Ve .PP The \f(CW\*(C`transport\*(C'\fR method specifies the Email::Sender transport that you want to use to send the email, and any options that need to be used to instantiate the transport. \f(CW$moniker\fR is used as the transport name; if it starts with an equals sign (\f(CW\*(C`=\*(C'\fR) then the text after the sign is used as the class. Otherwise, the text is prepended by \&\f(CW\*(C`Email::Sender::Transport::\*(C'\fR. .PP Alternatively, you can pass a complete transport object (which must be an Email::Sender::Transport object) and it will be used as is. .SS email .IX Subsection "email" .Vb 1 \& my $email_mime = $stuffer\->email; .Ve .PP This method creates and returns the full Email::MIME object for the email. .SS as_string .IX Subsection "as_string" .Vb 1 \& my $email_document = $stuffer\->as_string; .Ve .PP Returns the string form of the email. Identical to (and uses behind the scenes) \f(CW\*(C`Email::MIME\->as_string\*(C'\fR. .SS send .IX Subsection "send" .Vb 1 \& $stuffer\->send; .Ve .PP or .PP .Vb 1 \& $stuffer\->send({ to => [ $to_1, $to_2 ], from => $sender }); .Ve .PP Sends the email via Email::Sender::Simple. Envelope information can be specified in a hash reference. .PP On failure, returns false. .SS send_or_die .IX Subsection "send_or_die" .Vb 1 \& $stuffer\->send_or_die; .Ve .PP or .PP .Vb 1 \& $stuffer\->send_or_die({ to => [ $to_1, $to_2 ], from => $sender }); .Ve .PP Sends the email via Email::Sender::Simple. Envelope information can be specified in a hash reference. .PP On failure, throws an exception. .SH COOKBOOK .IX Header "COOKBOOK" Here is another example (maybe plural later) of how you can use Email::Stuffer's brevity to your advantage. .SS "Custom Alerts" .IX Subsection "Custom Alerts" .Vb 2 \& package SMS::Alert; \& use base \*(AqEmail::Stuffer\*(Aq; \& \& sub new { \& shift()\->SUPER::new(@_) \& \->from(\*(Aqmonitor@my.website\*(Aq) \& # Of course, we could have pulled these from \& # $MyConfig\->{support_tech} or something similar. \& \->to(\*(Aq0416181595@sms.gateway\*(Aq) \& \->transport(\*(AqSMTP\*(Aq, { host => \*(Aq123.123.123.123\*(Aq }); \& } .Ve .PP .PP .Vb 1 \& package My::Code; \& \& unless ( $Server\->restart ) { \& # Notify the admin on call that a server went down and failed \& # to restart. \& SMS::Alert\->subject("Server $Server failed to restart cleanly") \& \->send; \& } .Ve .SH "TO DO" .IX Header "TO DO" .IP \(bu 4 Fix a number of bugs still likely to exist .IP \(bu 4 Write more tests. .IP \(bu 4 Add any additional small bit of automation that isn't too expensive .SH "SEE ALSO" .IX Header "SEE ALSO" Email::MIME, Email::Sender, .SH AUTHORS .IX Header "AUTHORS" .IP \(bu 4 Adam Kennedy .IP \(bu 4 Ricardo SIGNES .SH CONTRIBUTORS .IX Header "CONTRIBUTORS" .IP \(bu 4 Aaron W. Swenson .IP \(bu 4 adam .IP \(bu 4 adamk@cpan.org .IP \(bu 4 adam@phase\-n.com .IP \(bu 4 Alastair Douglas .IP \(bu 4 Aristotle Pagaltzis .IP \(bu 4 Chase Whitener .IP \(bu 4 CosmicNet .IP \(bu 4 Dan Book .IP \(bu 4 fREW Schmidt .IP \(bu 4 John Napiorkowski .IP \(bu 4 Josh Stompro .IP \(bu 4 Kevin Tew .IP \(bu 4 Kieren Diment .IP \(bu 4 Kris Matthews .IP \(bu 4 Lee Johnson .IP \(bu 4 Manni Heumann .IP \(bu 4 Pali .IP \(bu 4 Ricardo Signes .IP \(bu 4 Ross Attrill .IP \(bu 4 Russell Jenkins .IP \(bu 4 Shawn Sorichetti .IP \(bu 4 Steve Dondley .IP \(bu 4 tokuhirom .SH "COPYRIGHT AND LICENSE" .IX Header "COPYRIGHT AND LICENSE" This software is copyright (c) 2004 by Adam Kennedy and Ricardo SIGNES. .PP This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.