Solved

Check email with perl

Posted on 2000-03-27
4
163 Views
Last Modified: 2010-03-05
Read the answer before, did this but failed

#!/usr/bin/perl
use strict;
use Mail::POP3Client;
print "Content-type: text/html", "\n\n";
my($POPServer) = 'my.mail.server';
my($user) = 'username';
my($password) = 'password';
my($pop) = new Mail::POP3Client($user, $password, $POPServer) || die "Unable to connect to $POPServer";
my($count, $i);
if ($count = $pop->Count)
{ print "$count Message";
  print 's' if $count > 1;
  print " Found:\n";
  for($i = 1; $i <= $count; $i++) { foreach ($pop->Head($i)) { print "\t$_\n" if m/^Subject/; } }
}
else { print "No Messages found\n"; }

keeps on getting "-1 Message Found". Why??!!
(Server is Apache on Unix)
0
Comment
Question by:yantz
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 1

Expert Comment

by:mrachow
ID: 2660879
Dear yantz,
your statement my($pop)= ...
don't show you problems while trying to connect to the server. The die statement would "appear" if the creation of the new instance  Mail::POP3Client would fail. So there should be an error while trying to connect. Maybe the server name couldn't resolved.
Greetings
0
 

Author Comment

by:yantz
ID: 2661072
thanx for answering! The script works as though it did call my mailbox but my mail server log doesn't record any log in attempt!? server name did resolve, thru ping and tracert, and I am able to retrieve normally with Netcape messenger using the same server name. It worked though on NT running Xitami!
0
 
LVL 1

Accepted Solution

by:
mrachow earned 50 total points
ID: 2668249
Hi yantz,

over some days I had now used that code snippet and it had worked perfectly. No message found if there isn't any mail, number of mails if some are there and finally -1 if it wasn't possible to connect to the POP3 mailbox. In case of -1 I verified then with netscape messenger and he was unable to connect to POP3 although the server itself was up (ping successful).
So actually I have no idea if for you netscape works.
Greetings
Michael
0
 

Author Comment

by:yantz
ID: 2668292
Actually, I found out the problem. It was my dns servers... duh!! What I did was go into POP3Client and add "print" messages here and there to see where it went wrong. It stopped at "connect ($sockaddr, AF................)". Printing the variables I found $host to be junks!!?!! instead of real address, which in turn found that "gethostbyname" couldn't work properly. and why? simply because my name server is not up yet...duh. Now its working perfectly. Thanx
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question