mail::webmail::gmail question

D

dupont2br

I am trying to use mail::webmail::gmail to automatically download all
attachments sent to a gmail account. i get daily reports and i want to
save the ZIP files attached to a local directory. I cannot figure out
how to save the attachment to a local directory once I have identified
messages with an attachment. Here is my code so far:

Thanks for your suggestions,
Eric
_______________________________________________________________________________

#!/usr/bin/perl

use Mail::Webmail::Gmail;
use Archive::Extract;

my $user = $ARGV[0];
my $pass = $ARGV[1];
my $folder = 'INBOX';

my $gmail = Mail::Webmail::Gmail->new(
username => $user, password => $pass,
);

my $messages = $gmail->get_messages(
label => $Mail::Webmail::Gmail::FOLDERS{ $folder }
);

foreach ( @{$messages}) {
my $email = $gmail->get_indv_email( msg => $_ );

if ( defined( $email->{ $_->{ 'id' } }->{ 'attachments' } ) )
{
foreach ( @{ $email->{ $_->{ 'id' } }-
{ 'attachments' } } ) {

### not sure if this is proper way of getting attachment
my $attach = $gmail->get_attachment( attachment => $_ );

### not sure what to do here to save to local directory
}
}
 
P

Paul Lalli

I am trying to use mail::webmail::gmail

No such module found. I'm assuming you meant Mail::Webmail::Gmail.
Case matters in Perl.
to automatically download all
attachments sent to a gmail account. i get daily reports and i want to
save the ZIP files attached to a local directory. I cannot figure out
how to save the attachment to a local directory once I have identified
messages with an attachment. Here is my code so far:

### not sure if this is proper way of getting attachment
my $attach = $gmail->get_attachment( attachment => $_ );
### not sure what to do here to save to local directory

According to the docs, get_attachment returns a reference to the data
of the attachment. (For example, if it's a text file, the actual text
in the file). So just open a new file on your machine and print the
data to it.

open my $att_fh, '>', 'attach.txt' or die $!;
print $att_fh ${$attach};
close $att_fh;

Hope that helps,
Paul Lalli
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top