hola. there sure is a function, and it's in Net::SMTP.
the OP's question can be answered without a
goto MIME::Lite - unless you need
to attach stuff. not that MIME::Lite is not a fine module. however, IMHO Net::SMTP is
absolutely fine & dandy for subject setting.
the following very small module wraps it and should
allow you to use it relatively painlessly. of course
there should be error handling etc etc. left as an
exercise for the reader...
# a simple module which uses Net::SMTP to mail the contents
# of a text file to a list of users. and with a
# subject too! note minor spoofing. adjust to taste.
package wmail;
use Net::SMTP;
sub mailfile{
my $smtpserver = 'server here plz';
my $file = shift;
die "no file" unless $file;
my $rcptsref = shift;
die "no recipients" unless ref $rcptsref;
my $subj = shift or "oops";
my @recipients = @{$rcptsref};
my $oldRs = $/;
undef $/;
open SOURCE, "$file" or die "can't open file $!";
my $totalcontents = <SOURCE>;
close SOURCE;
my $smtp = Net::SMTP;
$smtp = Net::SMTP->new($smtpserver);
$smtp->mail("informant");
$smtp->to(@recipients);
$smtp->data();
my $subjectline = "Subject: " . $subj . "\n";
$smtp->datasend($subjectline);
$smtp->datasend("\n");
$smtp->datasend($totalcontents);
$smtp->dataend();
# print $smtp->domain, "\n";
$smtp->quit;
}
1;
save that to say, wmail.pm, use in the following manner
use wmail;
@recipients = ('your rcpts here');
wmail::mailfile("myfile", \@recipients, "mysubject");
...wufnik
-- in the world of the mules there are no rules --
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.