Solved

Check email with perl

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
how to extract data from a table into a fixed length file 10 63
remove duplicates from the csv file 13 121
Perl script not writing to .csv file 6 123
iSeries PERL Scripts 7 201
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 …
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
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…

739 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