Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Check email with perl

Posted on 2000-03-27
4
Medium Priority
?
172 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 150 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

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

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

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 …
Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
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…
Six Sigma Control Plans

598 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