Solved

Check email with perl

Posted on 2000-03-27
4
153 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
  • 2
  • 2
4 Comments
 
LVL 1

Expert Comment

by:mrachow
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

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 …
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
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…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

744 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now