[Chicago-talk] emailing from perl

Jay Strauss me at heyjay.com
Wed Aug 1 21:24:41 PDT 2007


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

    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" );

        $ua = new LWP::UserAgent;
        my $resp = $ua->request($req);
        die "Error mailing document: ".$resp->message()."\n" if $resp->is_error;

    $/ = $tmpstr;

More information about the Chicago-talk mailing list