title: Extracting attachments from Lotus Notes Email with Java
body: <p>In my project I am attempting to read lotus notes email in the Inbox. Right now I have two emails in my inbox, each email has an attachment, and I am trying to open each email and download the attachment from that email. </p>
  
  <p>The issue I am having now is that my program is only reading the first email.</p>
  
  <pre><code>try
      {
          NotesThread.sinitThread();
  
          Session session = NotesFactory.createSession();
          Database database = session.getDatabase("servername", "mailbox link");
          View view = database.getView("$Inbox");
          Document document = view.getFirstDocument();
  
          while(document != null)
          {
  
              RichTextItem Body = (RichTextItem)document.getFirstItem("Body");
              Vector vector = Body.getEmbeddedObjects();
              Enumeration iterator = vector.elements();
  
              while (iterator.hasMoreElements())
              {
                EmbeddedObject eo = (EmbeddedObject)iterator.nextElement();
                if(eo.getType()==EmbeddedObject.EMBED_ATTACHMENT)
                  {
                      attachment = eo.getName();
                      eo.extractFile("destination" + eo.getName());
                      eo.remove();
                  }
  
              }//end of inner while
  
  
              logger.info("Received email and downloaded attachment");
              document = view.getNextDocument(document);
  
          } //end of outer while
  
  
  
      } 
      catch(NotesException nex)
      {
         logger.severe("Exception in INotes connection");
      }
      finally
      {
          NotesThread.stermThread();
  
      }
  </code></pre>
  
  <p>I thought the line --
        document = view.getNextDocument(document)</p>
  
  <p>would open the  next email in the Inbox. But I am only getting the first email as the result. </p>
  
  <p>Appreciate any pointers.</p>