SPUG: Posting a question for someone with e-mail bounce problems

Daryn Nakhuda daryn at marinated.org
Fri Jan 11 18:40:15 CST 2002


like anything in perl, there's a bunch of ways to go about doing this, but 
closest to what you're trying to do right now, would be to change what you 
have to reflect the below.. 

# you need these modules
use LWP::UserAgent;
use HTTP::Request;
use HTTP::Response;

# You should create your user agent outside of the loop and reuse it.
my $ua = new LWP::UserAgent();

# your loop
while (whatever) {
    # create the request with your pre-built url
    my $req = HTTP::Request->new(GET=>$theurl);

    # do the request and get the response
    my $resp = $ua->request($req);
   
    # make sure you got an okay response from the server
    if ($resp->is_success()) {
        my $content = $resp->content;
        # do whatever you want with the content
    }
    else {
        # there was a server error
    }
}




On Fri, 11 Jan 2002, Susanne Bullo wrote:

> Ok, thanks to you all I am using LWP::UserAgent and have it almost working
> :)  Here's the error I see when I try testing it:
> 
> Can't locate object method "method" via package
> "http://www.howto-workathome.com/cgi-bin/safelist/members.cgi?action=Send
> This Message&username=rocksolid&password=onesite&subject=This is a fifth
> test&message=www.sweethomes.com www.sweethome
> s.com www.sweethomes.com www.sweethomes.com www.sweethomes.com
> www.sweethomes.com www.sweethomes.com www.sweethomes.com www.sweethomes.com
> www.sweethomes.com " at /usr/lib/perl5/site_perl/5.005/LWP/UserAgent.pm line
> 163.
> Issuing rollback() for database handle being DESTROY'd without explicit
> disconnect().
> 
> Here is what I have for my code (don't laugh, it's my first official
> conglomeration for a script):
> 
> #!/usr/bin/perl
> use Time::Local;
> use POSIX qw(mktime);
> use DBI;
> use LWP::UserAgent;
> 
> &get_date;
> 
> sub get_date {
> 
>     @days   = ('Sunday','Monday','Tuesday','Wednesday',
>                'Thursday','Friday','Saturday');
>     @months = ('January','February','March','April','May','June','July',
> 	         'August','September','October','November','December');
> 
>     ($sec,$min,$hour,$mday,$mon,$year,$wday) =
> (localtime(time))[0,1,2,3,4,5,6];
>     $time = sprintf("%02d:%02d",$hour,$min);
> 
>     if ($year < 50){
> 	$year += 2000;
>     }
>     else {
> 	$year += 1900;
>     }
> 
>     $date = "$days[$wday], $months[$mon] $mday, $year at $time";
>     $mon2 = $mon + 1;
>     $date2 = "$mon2/$mday/$year";
> }
> 
> my $buffer = '';
> my $buffer2 = '';
> my $buffer3 = '';
> my $buffer4 = '';
> my $buffer5 = '';
> my $host     = 'localhost';
> my $database = 'safelist';
> my $username = 'admin';
> my $password = 'srb6653';
> 
> 
> my $dbh = DBI->connect("DBI:mysql:$database", $username, $password) || die
> "Failed DBI connect(): $!\n";
> 
> my $query = "SELECT safelists.email_to, safelists.username,
> safelists.password, email_txt.email_subject, email_txt.email_text,
> safelists.uid, members.email from safelists, schedule, email_txt, members
> where email_txt.id = schedule.SUN and schedule.system_name =
> safelists.system_name and members.id = safelists.uid and
> email_txt.email_subject != ''";
> $buffer .= "===> Executing Query: $query\n\n";
> my $sth = $dbh->prepare($query);
> my $rc  = $sth->execute();
> 
> while
> (my($email_to,$username,$password,$email_subject,$email_text,$system_name,$u
> id,$email) = $sth->fetchrow_array) {
> 
> $ua = new LWP::UserAgent;
> 
> my $url = "http://$email_to?action=Send This
> Message&username=$username&password=$password&subject=$email_subject&message
> =$email_text";
> my $file_path = './members/data/$username.$date.$time.txt';
> $ua->request($url, $file_path);
> 
> my $query2 = "SELECT safelists.uid, schedule.system_name from safelists,
> schedule where schedule.system_name = safelists.system_name and schedule.SUN
> != '0'";
> $buffer2 .= "===> Executing Query: $query2\n\n";
> my $sth = $dbh->prepare($query2);
> my $rc  = $sth->execute();
> 
> while (my($uid,$system_name) = $sth->fetchrow_array) {
> 
> my $datestamp = $date2;
> my $timestamp = $time;
> 
> my $query3 = "INSERT into reports (uid, system_name, last_success_run, id)
> values ('$uid', '$system_name', '$datestamp at $timestamp', '')";
> $buffer3 .= "===> Executing Query: $query3\n\n";
> my $sth = $dbh->prepare($query3);
> my $rc = $sth->execute();
> 
> }
> }
> 
> $dbh->disconnect;
> 0;
> 
> 
> Susanne Bullo - Sweet Homes
> <http://refer.ccbill.com/cgi-bin/clicks.cgi?CA=903921&PA=227740>
> DirectTV DSL <http://www.ezinfocenter.com/4216180/dsl>
> Get Paid to Read Email! <http://www.ezinfocenter.com/4216180/mm>
> 
> 
> 
>  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
>      POST TO: spug-list at pm.org       PROBLEMS: owner-spug-list at pm.org
>       Subscriptions; Email to majordomo at pm.org:  ACTION  LIST  EMAIL
>   Replace ACTION by subscribe or unsubscribe, EMAIL by your Email-address
>  For daily traffic, use spug-list for LIST ;  for weekly, spug-list-digest
>      Seattle Perl Users Group (SPUG) Home Page: http://zipcon.net/spug/
> 
> 

-- 



 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     POST TO: spug-list at pm.org       PROBLEMS: owner-spug-list at pm.org
      Subscriptions; Email to majordomo at pm.org:  ACTION  LIST  EMAIL
  Replace ACTION by subscribe or unsubscribe, EMAIL by your Email-address
 For daily traffic, use spug-list for LIST ;  for weekly, spug-list-digest
     Seattle Perl Users Group (SPUG) Home Page: http://zipcon.net/spug/





More information about the spug-list mailing list