[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl-WebCGI] POP3-Mail



At 1:02 AM +0100 2/20/00, Lasar Liepins wrote:
<snip>>
>For a new script which I am writing,
>I need some functions which connect
>to a POP3 mailbox, download all mail
>and store its body, subject and from
>address in some arrays, and delete
>the messages. After that the script
>should do some things with the data
>(that part of the script is already
>done).
>
>So, can anybody give me some pointers
>to what functions there are, and some
>code examples?
>I think I saw something using modules
>(or whatever they are called, those
>something::other things), but I never
>understood how to use those.

You'll want to read some documentation on object oriented Perl.  There's a
help section all about it.  It's good stuff to know,  even if you don't get
too much into detail with it.

>This script will run on a Linux server.

I needed to write something like this anyway, for a project of mine.
Between reading  an example in MPPE, and reading the pods for the various
modules, this what I've come up with - and it works.
#!/usr/bin/perl

use strict;
use Mail::Internet;
use Net::POP3;

my $mailbox = Net::POP3->new('your.mail.server');
my $msgCount = $mailbox->login('yourusername','yourpassword') or die
"couldn't connect!";
#You could replace the ->login with ->apop if your mailserver supports apop
and you have MD5 on your machine.
#try it and see.
my @mail;
for (my $nextMsg = 1;$nextMsg<=$msgCount;$nextMsg++)	{
	$mail[$nextMsg] = Mail::Internet->new($mailbox->get($nextMsg));
	$mail[$nextMsg]->print_body();
};
$mailbox->reset;
$mailbox->quit;
__END__

This will read in every  message from the mailbox, and print out the body.
It will leave the contents of the mailbox untouched.  Look for more
information in the pods for Net::POP3 and Mail::Internet.

-Jeff Lowrey



==== Want to unsubscribe from this list?
==== Send mail with body "unsubscribe" to macperl-webcgi-request@macperl.org