mail::webmail::gmail question

Discussion in 'Perl Misc' started by dupont2br@gmail.com, Jul 5, 2007.

  1. Guest

    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
    }
    }
     
    , Jul 5, 2007
    #1
    1. Advertising

  2. Paul Lalli Guest

    On Jul 5, 1:13 pm, "" <>
    wrote:
    > 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:


    <snip>

    > ### 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
     
    Paul Lalli, Jul 5, 2007
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. John Dalberg
    Replies:
    1
    Views:
    2,684
    =?Utf-8?B?U2l2YSBN?=
    Sep 19, 2005
  2. Li-fan Chen
    Replies:
    0
    Views:
    566
    Li-fan Chen
    Mar 2, 2006
  3. =?Windows-1252?Q?Enrique_Palomo_Jim=E9nez?=

    send mail through webmail

    =?Windows-1252?Q?Enrique_Palomo_Jim=E9nez?=, Sep 21, 2005, in forum: Python
    Replies:
    3
    Views:
    420
    Benji York
    Sep 22, 2005
  4. J Cardella
    Replies:
    3
    Views:
    209
    Johan Vromans
    Sep 28, 2004
  5. Replies:
    1
    Views:
    184
    J. Gleixner
    Jul 10, 2007
Loading...

Share This Page