in reply to Re: Mail::POP3Client email server to use
in thread Mail::POP3Client email server to use

Thanks for the replies. Here is the code I am using. I'm not too familiar with Perl so I really have no idea where I am going wrong. The output I get is just a warning about "main::trigger" only being used once. I've tried using the sample code you've posted and it doesn't work. I try to use the print $pop->Count(); in that sample code and it spits out -1, meaning it's not seeing any email. Any further suggestions? Thanks for the help.
$continue = "false"; until ($continue = "true") { use Mail::POP3Client; $pop = new Mail::POP3Client( USER => "me", PASSWORD => "password", HOST => "pop.google.com", AUTH_MODE => "PASS", DEBUG => 1 ); $MailState = $pop->State; if($MailState eq 'AUTHORIZATION') { die "\n\nBad user name or password!\n" } elsif($MailState eq 'DEAD') { die "\n\nMail server unreachable or unavailable!\n" } $messages = $pop->Count(); print $messages; if ($messages > 0) { # Read mail headers and get useful info for ($m = 1; $m<=$pop->Count; $m++) { $Headers = $pop->Head($m); if($Headers =~ /(\bReturn-Path.*)/g){ $RTNP = $1}else{ $RTNP = 'Return-Path:'} if($Headers =~ /(\bDate.*)/g){ $Date = $1}else{ $Date = 'Date:'} if($Headers =~ /(\bFrom.*)/g){ $From = $1}else{$From = 'From:'} if($Headers =~ /(\bTo.*)/g){ $To = $1}else{ $To = 'To:'} if($Headers =~ /(\bSubject.*)/g){ $Subj = $1}else{ $Subj = 'Subject:'} # Now Print it print "Message: ", $m, "\n", #$Date,"\n", #$To,"\n", #$From,"\n", #$RTNP, "\n", $Subj,"\n\n"; if ($Subj =~ /\bswift\sburst\alert.*/i) { $trigger = $m; $continue = "true"; } } } } #Look at the body of that email and do whatever with it... #$Headers = $mail->Head($trigger); #@_ = split(/\n/, $Headers); #$Body = $mail->Body($trigger); #print "\n\nMessage: ", $trigger, "\n\n"; #print $Body; #$pop->Close();

Edit g0n - added code tags

Replies are listed 'Best First'.
Re^3: Mail::POP3Client email server to use
by socketdave (Curate) on Jul 15, 2005 at 13:03 UTC
    First, you should probably edit your code to remove the username and pass (unless this is an account set up specifically for testing this script).

    It seems to me that you should move your initialization of your pop object to outside the until loop:
    use Mail::POP3Client; $pop = new Mail::POP3Client( USER => "username", PASSWORD => "password", HOST => "server.domain.tld", AUTH_MODE => "PASS", DEBUG => 1 ); $MailState = $pop->State; if ( $MailState eq 'AUTHORIZATION' ) { die "\n\nBad user name or password!\n"; } elsif ( $MailState eq 'DEAD' ) { die "\n\nMail server unreachable or unavailable!\n"; } $continue = "false"; until ( $continue = "true" ) { ...


    This won't get your whole script working, but with this change it does connect and check my messages.

    Hope this helps...
        What do you mean? I just want that variable to be set to something and then change it to something else if I find what I'm looking for. What should that code look like instead? Thanks, Austin
      Thanks again for the suggestions. I changed the loop, but I still can't connect. That email address is set up specifically for this task. Has anyone gotten this code to work with a gmail account? What opeating system are you using? Is anyone able to read my particular email (using the username and password I wrote above) using this code? Also, I added the DEBUG => 1 to the code and it didn't do anything different. What is supposed to happen? I have a feeling something is going wrong with the connection but I'm not sure how to see what. Thanks again, Austin
        I think what you really want to do is connect, grab all of the messages, determine if the message you're looking for is there and do something based on that. Is this correct? Do you want the script to continually reconnect and retry if it doesn't find what it's looking for? If so, do you want to to keep trying after it's foud it's first match?