title: Read Email and set body as TextView Javamail API
body: <p>I have Javamail API setup to send emails from a specific Gmail account. However, I am curious if there is a way to go through a small checklist, for example, if sender = "example@gmail.com" then grab the body of an incoming email and display the text content as a textView on an Android Application.</p>
  
  <p>I have found a few methods of reading emails from a Gmail account. An example of what I'm currently using is as follows:</p>
  
  <pre><code>public class ReadingEmail {
  
      public static void main(String[] args) {
  
          Properties props = new Properties();
          props.setProperty("mail.store.protocol", "imaps");
  
          try {
              Session session = Session.getInstance(props, null);
              Store store = session.getStore();
              store.connect("imap.gmail.com", "yourEmailId@gmail.com", "password");
  
              Folder inbox = store.getFolder("INBOX");
  
              inbox.open(Folder.READ_ONLY);
  
              Message msg = inbox.getMessage(inbox.getMessageCount());
              Address[] in = msg.getFrom();
  
              for (Address address : in) {
                  System.out.println("FROM:" + address.toString());
              }
  
              Multipart mp = (Multipart) msg.getContent();
              BodyPart bp = mp.getBodyPart(0);
  
              System.out.println("SENT DATE:" + msg.getSentDate());
              System.out.println("SUBJECT:" + msg.getSubject());
              System.out.println("CONTENT:" + bp.getContent());
  
          } catch (Exception mex) {
              mex.printStackTrace();
          }
      }
  }
  </code></pre>
  
  <p>An example of an email would be:</p>
  
  <p><a href="https://i.stack.imgur.com/h8KuJ.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/h8KuJ.jpg" alt="enter image description here"></a></p>
  
  <p>The output of the example in the console would be:</p>
  
  <p><a href="https://i.stack.imgur.com/GWH1X.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/GWH1X.jpg" alt="enter image description here"></a></p>
  
  <p>However, my issue with this is that instead of using println statements to write to the console, I would like to read the inbox, check if the sender is a specific pre-defined email address, and if so take the text only of that email and display it to the android screen as a textView.</p>
  
  <p>Any ideas would be greatly appreciated.</p>