Problem downloading attachments in Gmail

Hello,
I'm developing an application that sends mails with attachments from one gmail account to another gmail account and then I download those mails. The problem is that I can check the mails via pop3 and print their envelopes and that stuff but when I get the attachment via the dataHandler and getInputStream the message disappears from the message count and it's not possible to download it again, although if I enter to the gmail account the message is not even checked as read.
Can you help me? Thanks.

Ok so here it is the code for fetching mails with pop3. If I comment the "element.getDataHandler().getInputStream()" the mail doesn't disappear but then I can't get the attachment.
public void connect() throws Exception {
          String SSL_FACTORY = "javax.net.ssl.SSLSocketFactory";
          Properties pop3Props = new Properties();
          pop3Props.setProperty("mail.pop3.socketFactory.class", SSL_FACTORY);
          pop3Props.setProperty("mail.pop3.socketFactory.fallback", "false");
          pop3Props.setProperty("mail.pop3.port", "995");
          pop3Props.setProperty("mail.pop3.socketFactory.port", "995");
          pop3Props.setProperty("mail.pop3.rsetbeforequit", "true");
          URLName url = new URLName("pop3", "pop.gmail.com", 995, "", this.username, this.password);
          this.session = Session.getInstance(pop3Props, null);
          this.store = new POP3SSLStore(this.session, url);
          this.store.connect();
public void openFolder(String folderName) throws Exception {
          // Open the Folder
          this.folder = this.store.getDefaultFolder();
          this.folder = this.folder.getFolder(folderName);
          if (this.folder == null) {
               throw new Exception("Invalid folder");
          // try to open read/write and if that fails try read-only
          try {
               this.folder.open(Folder.READ_WRITE);
          } catch (MessagingException ex) {
               this.folder.open(Folder.READ_ONLY);
public void saveAttachment(String messageSubject, String path, String fileName) throws Exception {
Message[] msgs = this.folder.getMessages();
          // Use a suitable FetchProfile
          FetchProfile fp = new FetchProfile();
          fp.add(FetchProfile.Item.ENVELOPE);
          this.folder.fetch(msgs, fp);
          for (Message element : msgs) {
               if (element.getSubject().equals(messageSubject)){
                    System.out.println("MESSAGE " + element.getSubject() + ": Found! :)");
                    saveFile(path + fileName, element.getDataHandler().getInputStream());
                    break;
  public static void saveFile(String filename,
           InputStream input) throws IOException {
         if (filename == null) {
           filename = File.createTempFile("xx", ".out").getName();
         // Do no overwrite existing file
         File file = new File(filename);
         for (int i=0; file.exists(); i++) {
           file = new File(filename+i);
         FileOutputStream fos = new FileOutputStream(file);
         BufferedOutputStream bos = new BufferedOutputStream(fos);
         BufferedInputStream bis = new BufferedInputStream(input);
         int aByte;
         while ((aByte = bis.read()) != -1) {
           bos.write(aByte);
         bos.flush();
         bos.close();
         bis.close();
       }

Similar Messages

  • Can not download attachments in gmail

    I'm having problems downloading attachments in gmail.  Any ideas?

    I'll be honest, give up.  As many of us have found, Gmail on iPads is truly not compatible. Nor is Yahoo for that fact. Apple wants you to use their Apple Mail.
    I have a new iPad 3 and testing it against an Android tablet. I have no issues on an Android tablet.  My issue is attaching things in Gmail.  For instance, only the pics folders will open, but only pic folders contained in iPhoto or those I've taken with the iPad.  I've got other files stored on my iPad with pics, and don't get the option to attach anything in them.

  • Trouble downloading attachments in gmail/Firefox-IE

    Since this morning, I cannot download attachments in gmail using Firefox or IE (I did not try out Chrome). Since I have this problem in multiple browsers, the issue seems to stem from my computer, but still I'd appreciate any suggestions...

    I get this with all the attachments, though! Have a look at at the attached picture...

  • Download attachments from gmail using javamail

    I want to download the selected attachments from my gmail accout by using javamail.Is it possible?How can i acheive this?
    The actual need is i want to download only the selected files from my attachments.
    Thanks,
    vino

    I have downloaded attachments from my gmail account to local drive by using JavaMailApi.
    i will show the message subjects in my webpage.If i click the subject the corresponding attachment will be download.
    Here i have two questions,
    1)Can i display the attachment files in my page?
    2)I want to download the selected file from an attachment.suppose If i have an attachment with 5 files.
    and i select the 3rd file then the 3rd file will be download.how can i do it?

  • How to download attachments from gmail app in iphone

    I have installed gmail app in my iphone 6+. But when ever any mail having 5-6 attachments comes i am not able to download them. kindly tell me the way to download the attachments in gmail app.
    Thanks

    The following from Gmail support may help: https://support.google.com/mail/answer/2926444?hl=en

  • Problem synchronizing attachments from Gmail.

    Hi folks,
    I got a new Macbook Pro, and have set it up with my Gmail (through IMAP). Everything appears fine - all messages are in the inbox, and I can send and receive mail just fine.
    However, attachments have not been downloaded.
    If I turn Airport off, I can view messages offline - but without their attachments. If I turn the Airport back on, I can open a message and it will download the attachment in the background.
    How can I tell mail.app to do a full sync of the mailbox, including attachments?
    Thanks,
    David.

    Any chance of an update on how you solved it?

  • Safari has problem downloading gmail attachment with chinese filenames

    When using safari download attachments in gmail, the downloaded filenames are corrupted. all Chinese characters changed to ?
    For example ???.doc

    Same issue here! Unsolved after YEARS of this issue.
    I dig through the downloads folder and paste a copied file name at least 15 times a day.
    And Mountain Lion was supposed to be a big push for Chinese language users. Still a fail.
    Really want to be a Safari supporter - would love to see this solved, Apple.

  • How to download attachments excel file from gmail

    hi,
    i cant able to download attachments from gmail.com, ly i can able to view. can anyone explain how to download attachments from mail.
    rgds
    pravin

    You can't download attachments with an email account via webmail access using a browser.
    You can view attachments in a received email when accessing the account with the iPhone's Mail app and you can save photo attachments to the iPhone's Camera Roll and save PDF attachments to the iBooks app, but all other attachments such as a Word or Excel document can be viewed only.

  • Downloading attachment in gmail

    I am having trouble downloading attachments in Gmail emails while using Safari. When I click on the download link, the attachments do not download. Thoughts?

    Empty Caches
    1. Safari > Preference > Advanced
        Checkmark the box for "Show Develop menu in menu bar".
        "Develop" menu will appear in the Safari menu bar.
        Click Develop and select "Empty Caches" from the dropdown.
    2. Quit Safari if open.
        Option click the "Go" menu in the Finder menu bar.
        Select "Library" and then "Caches".
        Look for the folder 'com.apple.Safari"
        Right click "com.apple.Safari" and select "Move to Trash"
        Relaunch Safari.

  • Error when downloading attachments and the calendar

    Hi!
    We're having problems downloading attachments in the forum, the calendar and reports from iLearning with Internet Explorer.
    The error message states:
    Internet Explorer cannot download (url goes here)
    Internet Explorer was not able to download this Internet site. The requested site is either unavailable or cannot be found. Please try again later.
    We're running iLearning on https.
    Tips and solutions are welcome :)

    Link for Download & Install & Setup & Activation problems may help
    -Chat http://www.adobe.com/support/download-install/supportinfo/
    OR
    Some download & install troubleshooting links
    -Comodo Security kills download http://forums.adobe.com/thread/1460361?tstart=0
    -http://helpx.adobe.com/x-productkb/policy-pricing/activation-network-issues.html
    -http://helpx.adobe.com/creative-cloud/kb/error-downloading-cc-apps.html
    -http://forums.adobe.com/community/download_install_setup
    -http://helpx.adobe.com/creative-cloud/kb/troubleshoot-cc-installation-download.html
    -http://helpx.adobe.com/x-productkb/global/errors-or-unexpected-behavior-websites.html
    -http://helpx.adobe.com/creative-cloud/kb/unknown-server-error-launching-cc.html
    -Server won't connect https://forums.adobe.com/thread/1233088
    -SPECIAL FOR MAC USERS
    -Mac 10.9.3 workaround https://forums.adobe.com/thread/1489922
    -more Mac 10.9.3 https://forums.adobe.com/thread/1491469
    -Enable Mac Root User https://forums.adobe.com/thread/1156604
    -more Root User http://forums.adobe.com/thread/879931
    -and more root user http://forums.adobe.com/thread/940869?tstart=0

  • Since the update to 7.0.1 I am unable to open download updates to IE 8. Nor can I download a fresh version of AOL 9.0vr or download attachments from web beased e-mails. Is there a problem with Firefox, please?

    I have several problems.
    1. I cannot download attachments from web based e-mail accounts (AOL & Tesco.Net) without Firefox crashing and having to be restarted.
    2. I can no longer start Internet Explorer 8
    3. I can't download a new version of IE 8 or AOL 9.0VR. The .exe files download and run but the remainder of the download and installation process does not happen.

    If you can’t use a Bluetooth accessory or car kit

  • E90 - attachments in Gmail

    Hi all,
    I have a problem with working on Gmail. When I try to download attachment I'm not able to do so. Also, when I click on "View" option to see attached image, browser opens new window but it doesn't display the image.
    9500 didn't have this problem.
    Any suggestion??

    @mai0805
    yes you can do this with pdf, since pdf is recognazable file type by e90.
    BUT, if you have some other type of file, for instance Autocad drawing, RAR file or something similar, forget about it.
    I was in situation where I needed such funcionality. I guess it's rare but it can happen.
    Add this to the long list vmoisa: on 9500 it was normally possible to handle attachments of any kind in a computer manner (from e-mail client or web browser), download and choose the location to save. On E90 it is not.
    I can't say I don't like my E90, but I really miss S80 also. Nokia, you have made a bad decision dropping it!
    Message Edited by sugarsmoking on 13-Feb-2008 08:45 AM
    Message Edited by sugarsmoking on 13-Feb-2008 08:47 AM

  • Downloading attachments in Safari

    For about the last week, I can't download Word or PDF or .zip attachments in Gmail through Safari.  Nothing happens when I click on the Download arrow in an email attachment.   (The problem also exists in Firefox).
    Safari Preferences are set to open attachments in Downloads.
    Interestingly, I've also noticed that when I click on Gmail to log out, my Profile photo has disappeared.
    Now this problem exists on my home computer, but there is no problem on my work computer using Google in Windows.  I am in Kazakhstan.
    And further, my wife is having just the same problems, but she is in Leeds UK.  She too, can open such attachments if she uses Google via Windows on her work computers. 

    From your Safari menu bar click Safari > Preferences then select the Privacy tab.
    Click:   Remove All Website Data
    Then delete the cache.
    Open a Finder window. From the Finder menu bar click Go > Go to Folder
    Type or copy paste the following
    ~/Library/Caches/com.apple.Safari/Cache.db
    Click Go then move the Cache.db file to the Trash.
    Quit and relaunch Safari to test.
    If nothing above helped, troubleshoot Safari extensions.
    From the Safari menu bar click Safari > Preferences then select the Extensions tab. Turn that OFF, quit and relaunch Safari to test.
    If that helped, turn one extension on then quit and relaunch Safari to test until you find the incompatible extension then click uninstall.

  • ? Can't print PDF attachments to gmail since installing 11.06

    I am on Windows 7 and Firefox,  Since installing 11.06 I can't print PDF attachments to gmail messages.  I get a (false) message that file cannot be printed, because no pages have been selected.  I tried uninstalling 11.06 and downloading and insatalling it again,  Same result. Any way to download a backlevel version for the time being?  Would appreciate any other sugestions.. 

    Disabling Protected Mode as suggested solved the problem.  It seems to me the impact of Protected Mode should have been highlighted with a warning at the download site.  Alternatively, and in my opinion preferably, Protected Mode enabled should not have been made the default. -shel488

  • Can't email .pages attachments in gmail

    Since upgrading to Mavericks, I cannot email .pages attachments in Google mail. I've been reading that other people are experiencing this problem but everything I've found is from late 2013. Just wondering if there is a fix or workaround to this.
    Thank you.

    If a person uses Apple's native Mail App that came on the Mac or iOS devices...then is will send attachments of the newest "Mavericks" versions of Pages, Numbers and Keynote. If a person tries to do this from within a Web Browser it doesn't seem to work (as I've recently tested from information from of our churches staff who only use the Web Interface). So, I'm not sure if Google changed something with thier Web Browser version recently or not, since I've always used the native Mail App on all my Macs and iOS devices.
    So, there used to be a problem sending attachments from within the Mail App several months ago...but that was fixed by Apple (again several months ago).
    Hope that helps...
    I highly recommend using the built in Mail App (Email Client).
    Multiple Email Accounts:
    An Email Client allows multiple email accounts from different email providers to all be used simultaneous in one simple to use interface without any problematic POP forwarding settings or delayed delivery problems. i.e. It will gather and display email from Yahoo, Gmail, iCloud, AOL, Microsoft Exchange or any other email provider.
    Accounts can still be viewed separately or all together:
    All email accounts can still be viewed separately or all together with a click of the mouse or a tap of the screen, again without any forwarding settings. i.e. It's great for keeping personal and/or work accounts separate, and it also allows multiple signatures which helps relay professionalism, consistency and saves a little typing, too.
    Select Multiple Messages:
    A person can select multiple messages (even from different email accounts or email providers), and move, copy, delete, or even forward them all at the same time with a single action.
    Work Offline:
    It allows a person to continue working offline. i.e. no matter if Wi-Fi or the internet goes down or is unavailable in a certain area.
    Advanced Rules and Filtering Based on Multiple Factors:
    A person can set rules or advanced rules and filtering based on multiple factors (words, senders, subjects, headers, etc.)
    Quick Look:
    And, if you’re on a Mac, you can used features like "Quick Look" to view full Microsoft Office or Apple iWorks (Pages, Numbers, or Keynote) documents right inside your Mail App.
    No Extra Apps to Download:
    As it's already pre-installed on all Apple computers and iOS devices, so it's one less App to download or maintain.
    Mac and iOS Versions Both Work Similarly:
    Both the desktop and mobile versions work very similarly.
    Easy to Maintain:
    Apple automatically maintains it with each System Update, which is great for security, too.
    Attachments are Easy (with less importing/exporting):
    Working with attachments is super easy without any external importing or exporting (for example: items can be imported and exported directly to and from iPhoto, Contacts, Calendars etc. without any duplication).
    It takes full advantage of the built in systemwide OS X / iOS features that popup:
    Spell Checker
    User Learned Spell Checker
    Dictation and Speak Selection
    Full Thesaurus (no internet required)
    Full built in Oxford Dictionary (no internet required)
    Wikipedia (on demand with an internet or data plan connection)

Maybe you are looking for

  • How to find out what text encoding has been used in mp3 tag

    Hello I have some foreign songs that I am importing into itunes. When a song called "04.公路 塵埃 北合起." gets imported, it comes up in itunes as "04.§Ω∏Ù π–ÆJ •¶X∞" Now I don't know a lot about different text encodings, but from what I've read on the foru

  • My new program DUMP :

    My new program is dumping at the below stmt: IF NOT gt_soldto1[] IS INITIAL.     SELECT *                " kunnr name2 j_3astcu       FROM kna1       INTO CORRESPONDING FIELDS OF TABLE gt_kna1      FOR ALL ENTRIES IN gt_soldto1      WHERE ( name2   L

  • How to give date in where of select statement

    hi iam using this stmt   SELECT  AUFNR    WERKS   KDAUF   KDPOS    PLNBEZ    GAMNG           GMEIN      GSTRP       GLTRP       FROM CAUFV       INTO TABLE TB_CAUFV           WHERE AUFNR IN S_AUFNR          AND KDAUF IN S_KDAUF          AND WERKS IN

  • Accordion widget content height

    I'm using an accordion widget for the navigation of a site.  Some of the sections have sub-sections and other do not. Is it possible to remove the "content area" of an accordion widget but keep the label?  I tried to set the height of the content are

  • Where to download oracle webcenter sites ???

    hi i am trying to download oracle webcenter sites ,we would like to test .when i searched at oracle download and e-delivary i couldnt find the setup files ,it is only available in oracle shop to be bought . is there anywhere to find the setup for dev