Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: Mail::POP3Client email server to use

by socketdave (Curate)
on Jul 14, 2005 at 19:45 UTC ( [id://475031]=note: print w/replies, xml ) Need Help??


in reply to Mail::POP3Client email server to use

Could you post your code and the output you're receiving?

UPDATE:

This works for me (straight from the docs):
#!/usr/bin/perl use Mail::POP3Client; $pop = new Mail::POP3Client( USER => "user", PASSWORD => "pass", HOST => "server.domain.tld" ); for ( $i = 1 ; $i <= $pop->Count() ; $i++ ) { foreach ( $pop->Head($i) ) { /^(From|Subject):\s+/i and print $_, "\n"; } print "\n"; }

Replies are listed 'Best First'.
Re^2: Mail::POP3Client email server to use
by austinz (Initiate) on Jul 15, 2005 at 01:01 UTC
    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

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

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (5)
As of 2024-03-29 10:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found