Solved

Check email with perl

Posted on 2000-03-27
4
156 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
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Existing perl code to be changed for ftp to sftp handling 14 162
work on ods spreadsheet with perl in ubuntu 4 75
Perl 101 11 72
ppm conversion to curl on a module install 8 80
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…
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…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

910 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

20 Experts available now in Live!

Get 1:1 Help Now