Solved

usin perl to Read email

Posted on 2003-11-25
5
449 Views
Last Modified: 2010-03-04
Hi All
I need to read an email every time "X email account" receives mails using perl and
i only want to print the subject of the received mail to the screen. thanks in advance
any help will be apriciated.

chz
0
Comment
Question by:Thlware
  • 3
  • 2
5 Comments
 
LVL 24

Expert Comment

by:shivsa
ID: 9822824
0
 
LVL 2

Author Comment

by:Thlware
ID: 9822869
I have a registered email account on a mail sever pop3 i just need to monitor and  print the subject of emails every time there is a new mail.

chz
0
 
LVL 24

Accepted Solution

by:
shivsa earned 225 total points
ID: 9822979
First, u have to install mail pop 3 client.

download and install in the standard way (it doesn't require a compiler)

http://perl.com/cgi-bin/cpan_mod?module=Mail::POP3Client

After that's installed, try the following (make sure to put in the name of your pop server, as well as the appropriate user name and password):

use strict;
use Mail::POP3Client;

my($POPServer) = 'pop3.mail.com';
my($user) = 'me';
my($password) = 'secret';

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";
}

thanks to b2pi.

0
 
LVL 2

Author Comment

by:Thlware
ID: 9823041

Mail::POP3Client; this module seems to be a Unix/linux type module is there alternative module for windows
0
 
LVL 24

Expert Comment

by:shivsa
ID: 9823061
it does not matter as long as perl is using this module, syntex in perl is same on unix/windows.
try to install it and see of this script solve your things.
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

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…
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

895 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

14 Experts available now in Live!

Get 1:1 Help Now