Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: Setting subject with Net::SMTP

by wufnik (Friar)
on Jul 26, 2004 at 19:50 UTC ( [id://377543]=note: print w/replies, xml ) Need Help??


in reply to Setting subject with Net::SMTP

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 --

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://377543]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (8)
As of 2024-04-25 11:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found