Results 1 to 8 of 8

Thread: [SOLVED] Script to download attachments from Gmail?

  1. #1
    Join Date
    Aug 2008
    Location
    Brazil
    Beans
    12,497
    Distro
    Ubuntu Studio 12.04 Precise Pangolin

    [SOLVED] Script to download attachments from Gmail?

    I need a script to download an attachment form Gmail and save it on a specific folder. Does someone knows how to do it?

    There is a service in my country that provides a xmltv.xml file with TV schedules, so I can use it on the EPG software. The problem is that they don't provide a download link because of copyright issues, so you have to register an e-mail account so they can send the file to you.

    I have already managed to automate the deliver of the xml file to my Gmail account using curl, but I can't retrieve it automatically from Gmail. This is the last step I need to perform in order to make my tv schedules update automatically.

    Edit: solution on post #6
    Last edited by lovinglinux; October 12th, 2008 at 07:34 PM.

  2. #2
    Join Date
    Jan 2007
    Beans
    6,537
    Distro
    Ubuntu 13.04 Raring Ringtail

    Re: Script to download attachments from Gmail?

    You could try using one of the terminal-based email clients (eg: Mutt) to fetch your email, then once it's stored locally searching for the file and moving it to the destination directory should be pretty straightforward. The whole script could be automated.

    Could be fiddly to set up the email side of it though.

  3. #3
    Join Date
    Aug 2008
    Location
    Brazil
    Beans
    12,497
    Distro
    Ubuntu Studio 12.04 Precise Pangolin

    Re: Script to download attachments from Gmail?

    Thanks. I will try this way.

  4. #4
    Join Date
    Feb 2008
    Beans
    392

    Re: Script to download attachments from Gmail?

    There is an extension for firefox called "iMacros" that may (or may not) help you.

    It is built for firefox, so it should do the trick. But I have not tried it so please don't sue me if it does not work
    Customer: (angrily) "You said I would get 98 windows with this computer. Where are they?"
    Recent video card: Supports two DIFFERENT applications open at one time;
    My 6-year-old laptop with integrated graphics does that just fine

  5. #5
    Join Date
    Aug 2008
    Location
    Brazil
    Beans
    12,497
    Distro
    Ubuntu Studio 12.04 Precise Pangolin

    Re: Script to download attachments from Gmail?

    Quote Originally Posted by Gannon8 View Post
    There is an extension for firefox called "iMacros" that may (or may not) help you.

    It is built for firefox, so it should do the trick. But I have not tried it so please don't sue me if it does not work
    Thanks for the tip. I know that extension, but never really used it. Nevertheless, I'm really looking for a script, because all other steps I need to automate the process are performed this way.

  6. #6
    Join Date
    Aug 2008
    Location
    Brazil
    Beans
    12,497
    Distro
    Ubuntu Studio 12.04 Precise Pangolin

    Re: Script to download attachments from Gmail?

    After a lot of research I finally figure out a simple way of doing this using IMAP and a shell script. I decided to post a step-by-step description if someone needs this.

    1 - Install offlineimap and mpack

    Code:
    sudo apt-get install offlineimap mpack
    2 - Create a folder ~/mail for storing the Gmail messages

    3- Create a text file and save it as ~/.offlineimaprc

    This is the configuration file for offlineimap which will sync your Gmail with local maildir files, using IMAP. Add the following code to it:

    Code:
    [general]
    accounts = GMail
    
    ui = Noninteractive.Basic
    
    [Account GMail]
    localrepository = GMailLocalMaildirRepository
    remoterepository = GMailServerRepository
    
    [Repository GMailLocalMaildirRepository]
    type = Maildir
    localfolders = ~/mail/
    
    [Repository GMailServerRepository]
    type = IMAP
    remotehost = imap.gmail.com
    remoteuser = yourgmailaccount@gmail.com
    remotepass = yourgmailpassword
    ssl = yes
    Then run the following command on a terminal:

    Code:
    offlineimap && munpack /home/user/mail/LABEL/new/*
    The offlineimap command will sync Gmail with local files and munpack will extract any new messages and attachments in the "LABEL" folder, where each folder (label) correspond to Gmail labels.

  7. #7
    Join Date
    Jan 2008
    Beans
    1

    Re: Script to download attachments from Gmail?

    Quote Originally Posted by lovinglinux View Post
    After a lot of research I finally figure out a simple way of doing this using IMAP and a shell script. I decided to post a step-by-step description if someone needs this.

    1 - Install offlineimap and mpack

    Code:
    sudo apt-get install offlineimap mpack
    2 - Create a folder ~/mail for storing the Gmail messages

    3- Create a text file and save it as ~/.offlineimaprc

    This is the configuration file for offlineimap which will sync your Gmail with local maildir files, using IMAP. Add the following code to it:

    Code:
    [general]
    accounts = GMail
    
    ui = Noninteractive.Basic
    
    [Account GMail]
    localrepository = GMailLocalMaildirRepository
    remoterepository = GMailServerRepository
    
    [Repository GMailLocalMaildirRepository]
    type = Maildir
    localfolders = ~/mail/
    
    [Repository GMailServerRepository]
    type = IMAP
    remotehost = imap.gmail.com
    remoteuser = yourgmailaccount@gmail.com
    remotepass = yourgmailpassword
    ssl = yes
    Then run the following command on a terminal:

    Code:
    offlineimap && munpack /home/user/mail/LABEL/new/*
    The offlineimap command will sync Gmail with local files and munpack will extract any new messages and attachments in the "LABEL" folder, where each folder (label) correspond to Gmail labels.
    Great guide I was wonder if there was a way to download just one folder from gmail

  8. #8
    Join Date
    Aug 2008
    Location
    Brazil
    Beans
    12,497
    Distro
    Ubuntu Studio 12.04 Precise Pangolin

    Re: Script to download attachments from Gmail?

    Quote Originally Posted by robsshadow View Post
    Great guide I was wonder if there was a way to download just one folder from gmail
    Thank you. I don't think is possible to download just a folder using offlineimap, because it would mess with sync.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •