What would be the best Perl module to use to read e-mails from a POP3 account?
I am trying to write a Perl script that accesses a POP3 e-mail box and prints out the bodies all of the e-mails that it sees. Ideally I would also like to be able to know certain things about each e-mail such as who the e-mail is from, to, subject line, date, etc.
I am only concerned with the text/plain or text/html portions of the e-mails. I do not need to parse or retrieve e-mail attachments. Also, if the e-mail contains both a text/plain and text/html portion, I would like to be able to access the text/html portion with the HTML tags intact and without all of the encoded e-mail headers.
So far this is what I have:
use Mail::Box::POP3; $url = "pop3://username:password\@server.address.com"; $pop = Mail::Box::POP3->new($url);
What do I write next? How do I start looping through the e-mails? Is this even the correct module to use?
Thanks so much for all of your help.
UPDATE!! a few minutes later!
I was able to access and loop through e-mails in the POP3 account with this simple code:
use Mail::Box::Manager; $mgr = Mail::Box::Manager->new; $pop = $mgr->open(type => 'pop3', username => 'my@email.address', password => 'mypasswordxxxxx', server_name => 'my.mail.server'); foreach $msg ($pop->messages) { $content_type = $msg->contentType; $from_address = $msg->sender->address; $body = $msg->decoded; }
Now, the question is, how do I extract the HTML portion of the body of the e-mail from the rest of the body? For example, here is what the body looks like in its current form:
This is a multi-part message in MIME format. ------=_NextPart_000_0009_01CA7F30.7F3A37C0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit From: sender@email.address Sent: Wednesday, December 16, 2009 9:28 PM To: test@email.address Subject: This is the subject This is the body. ------=_NextPart_000_0009_01CA7F30.7F3A37C0 Content-Type: text/html; charset="us-ascii" Content-Transfer-Encoding: quoted-printable <html> <head> <body> This is the body. </body> </html> ------=_NextPart_000_0009_01CA7F30.7F3A37C0--
So my question is, how do I extract only the part between the <html> and </html> tags?
Thanks so much.
In reply to best module to read e-mail from a POP3 account by keiusui
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |