[Chicago-talk] emailing from perl
Eric Ellington
e.ellington at gmail.com
Thu Aug 2 07:19:32 PDT 2007
If you have access to an SMTP server you can try out Mail-Sender. I
used it yesterday for the first time on a windows machine and it
worked as advertised.
use Mail::Sender;
$sender = new Mail::Sender {smtp => 'mail.yourmailserver.com', from
=> 'me at test.com', on_errors => 'code'};
$sender->MailMsg(
{to => 'you at test.com', subject => 'Here is the data', msg => "I'm
sending you the list you wanted."}
) or die "ERROR:$Mail::Sender::Error $!\n";
On 8/1/07, Jay Strauss <me at heyjay.com> wrote:
> Hi,
>
> I'm trying to use this program called "websec". Its sort of a poor
> man's RSS. Its supposed to look at a webpage and notice if its
> changed, and if so, email the updated page.
>
> I can't get the emailing to work on my machine. I snipped out the
> code in the program that does the emailing (below). I don't get how
> the email would be sent. Doesn't there need to be some sort of email
> client setup to send this to an SMTP server or something?
>
> # Mail HTML document.
> # Params: filename, subject, recipient
> # Returns: none
> sub MailDocument() {
> my $filename = shift (@_);
> my $subject = shift (@_);
> my @recipients = split /,/, shift (@_);
> my $from = shift (@_);
> my $tmpstr = $/;
>
> undef $/;
> open( FILE, "$filename" ) or die "Cannot open $filename: $!\n";
> my $content = <FILE>;
> close(FILE);
>
> foreach $email (@recipients) {
> $req = HTTP::Request->new( POST => "mailto:" . $email );
> if ( $from ne "" ) {
> $req->header( "From", $from );
> $req->header( "Sender", $from );
> }
> $req->header( "Subject", $subject );
> $req->header( "Content-type", "text/html" );
> $req->header( "Content-Transfer-Encoding", "7bit" );
> $req->header( "MIME-Version", "1.0" );
> $req->content($content);
>
> $ua = new LWP::UserAgent;
> my $resp = $ua->request($req);
> die "Error mailing document: ".$resp->message()."\n" if $resp->is_error;
> }
>
> $/ = $tmpstr;
> }
> _______________________________________________
> Chicago-talk mailing list
> Chicago-talk at pm.org
> http://mail.pm.org/mailman/listinfo/chicago-talk
>
--
Eric Ellington
e.ellington at gmail.com
More information about the Chicago-talk
mailing list