Kiko has asked for the wisdom of the Perl Monks concerning the following question:

Hi All, I wrote this very simple script to check your email over the web. Unfortunately, it is not working and i don't know if it's because i'm sitting behing a firewall at work. Please play with it and let me know what you guys think. Thanks, Kiko
#!/perl/bin/perl use CGI qw(:standard); use Net::POP3; use strict; print header(); #Get CGI parameters my $hostname= param("hostname"); my $account= param("account"); my $password= param("password"); #Connect to Host my $connect = Net::POP3->new($hostname) or die "Unable to establish a +POP3 connection to $hostname.\n"; #Authenticate User defined($connect->login($account, $password)) or die "Unable to authen +ticate ($account, $password) at $hostname.\n"; #Retrieve Messages my $messages = $connect->list or die "Unable to retreive list of avaib +le mesages.\n"; #Display Messages my $msg; my $grab; foreach $msg (keys %$messages) { $grab .="<tr><td>$connect->top($msg)</td></tr>"; } print<<HTML; <html> <head><title>Web Mail</title> </head> <body> <table width=700> $grab </table> </body> </html> HTML

Replies are listed 'Best First'.
Re: Simple Email Check
by Henri Icarus (Beadle) on Jun 07, 2001 at 05:49 UTC
    Three things:

    1) For testing purposes use

    use CGI::Carp qw(fatalsToBrowser);

    This will show you your errors in the browser instead of making you have to look in the error logs

    2) Add in lots more print statements as you go along. For example you'll want to print out:

    $message_count = scalar keys (%$messages);

    to see if you actually have any messages!

    3) And finally $connect->top($msg) doesn't return a string, it returns an array ref, so your loop should look like this instead:

    foreach $msg (keys %$messages) { my $r = $connect->top($msg); my $m = join ("<BR>",@$r); $grab .="<tr><td> $m </td></tr>"; }

    I ran your script with those changes and it worked just fine. Good luck!

      Hi,

      I've made the changes you told me and it works fine from
      home, thanks. Now the reason i wrote this script was so
      that i can check my pop3 emails from work since they block
      access to yahoo, hotmail, and any other pop3 emails out
      there. I'm sitting behind a firewall and i think that's
      what's preventing me from connecting from work. It
      say's "Unable to establish a POP3 connection to
      pop.mail.yahoo.com." If you guys know a way around this
      maybe by connecting through a proxy or something let me
      know. That will be very helpful and greatly appreciated.

      Thanks,
      Kiko
        What you wrote *is* a proxy. If you install it on a server not behind a firewall you should be able to use it from work.
Re: Simple Email Check
by petdance (Parson) on Jun 07, 2001 at 01:45 UTC
    Define "not working". Do you get an error? Does your server catch fire? Do you get the wrong person's email? Does the password fail?

    Without knowing what "not working" means, we can't help.

    Also, remember Question #1 of non-working CGI scripts:

    Does it work when you run it from the command line?

    xoxo,
    Andy

    %_=split/;/,".;;n;u;e;ot;t;her;c; ".   #   Andy Lester
    'Perl ;@; a;a;j;m;er;y;t;p;n;d;s;o;'.  #   http://petdance.com
    "hack";print map delete$_{$_},split//,q<   andy@petdance.com   >
    
      Hi, I guess i was a little vague. When i run the script i get a blank page. And it does work when i run it from the command line. Here is the login script:
      #!/perl/bin/perl use CGI qw(:standard); print header(); print <<HTML; <HTML> <HEAD> <TITLE> Check email </TITLE> </HEAD> <BODY> <form name"email" method="post" action="check_email.pl"> <table align="center" cellspacing="0" cellpadding="1" border="1" width +="275" height="150"> <tr><td bgcolor="#999999"> <table width="265" border="0" cellpadding="2" cellspacing="0" height +="145"> <tr> <td bgcolor="#ccff99"><font face="arial,helvetica,sans-serif" size +="2">Hostname:</font></td> <td><input type="text" name="hostname" width="20"></td> </tr> <tr> <td bgcolor="#ccff99"><font face="arial,helvetica,sans-serif" size +="2">Account:</font></td> <td><input type="text" name="account" width="20"></td> </tr> <tr> <td bgcolor="#ccff99"><font face="arial,helvetica,sans-serif" size +="2">Password:</font></td> <td><input type="password" name="password" width="20"></td> </tr> <tr> <td>&nbsp;</td> <td><input type="submit" value="Check">&nbsp;&nbsp;<input type="re +set" value="Reset"></td> </tr> </table> </td></tr> </table> </form> </BODY> </HTML> HTML
      Thanks for your help, Kiko
Re: Simple Email Check
by xphase_work (Pilgrim) on Jun 07, 2001 at 01:29 UTC
    What is the error that you are getting?
    If it is due to a firewall, you should get
    the "Unable to Establish a POP3 connection" error,
    but this error could also be because your POP3 server
    is down.

    --xPhase