bkiahg has asked for the wisdom of the Perl Monks concerning the following question:

Hello Wise Monks,

I once again come seeking your wise council. I am wanting to write a script that goes out to a mail account every few mins. Download an e-mail and then strip the attachment and save it in a directory. This is going on a windows box.

I did a search on cpan and it turned up a plethora of mail modules and attachment strippers that go along with them. My question is, which of these would be best suited for this task?

Thank you in advance for your guidance.

** Edit **
This is a POP account and they're TIFF images as attachments.

Replies are listed 'Best First'.
Re: E-Mail Attachment Downloader
by gellyfish (Monsignor) on Sep 08, 2005 at 20:12 UTC

    This can be fairly trivially achieved with Net::POP3 and Email::MIME - the following example is not exhaustive and only partially tested (I didn't have any MIME mail in my mailbox at the time), but should put you in the right direction:

    #!/usr/bin/perl use strict; use warnings; use Net::POP3; use Email::MIME; my $pop3server = 'your.server.here'; my $username = 'yourlogin'; my $password = 'yourpassword'; my $popclient = Net::POP3->new( $pop3server, Timeout => 60 ); if ( $popclient->login( $username, $password ) > 0 ) { foreach my $msgnum ( keys %{$popclient->list()} ) { my $msg = $popclient->get($msgnum); my $message = join '', @{$msg}; my $parsed = Email::MIME->new($message); foreach my $part ( $parsed->parts() ) { my $filename = $part->filename(1); open FILE, '>', $filename or do { warn "can't open $filename - $!"; next; }; print FILE $part->body(); close FILE; } $popclient->delete($msgnum); # remove if you want to keep th +e messages } } $popclient->quit();
    Hope that helps

    /J\

Re: E-Mail Attachment Downloader
by davidrw (Prior) on Sep 08, 2005 at 20:01 UTC
    First question is: what kind of mail account is this (IMAP? POP? hotmail/yahoo/gmail/other webmail? (and does the script need to support more than one?)
      POP account, apologies.