title: How to send email in background in Android?
body: <p>For my app, I have retrieved my message <code>inbox/sent</code>. Now I want to send that retrieved data on my email address.how can it be? Is any authentication required for it? Also I have tried to download the authentication files (authentication.jar,mail.jar) but can't succeeded.</p>
  
  <pre><code>long currentTime = System.currentTimeMillis();
      long pastThreeHour = currentTime - (AlarmManager.INTERVAL_HOUR * 3);
      String[] selectionArgs = { "" + pastThreeHour, "" + currentTime };
  
      Cursor cursor = contentResolver.query(uri, null, selection, selectionArgs, "date DESC");
  
      if (cursor != null &amp;&amp; cursor.getCount() &gt; 0) {
          while (cursor.moveToNext()) {
  
              String number = cursor.getString(cursor.getColumnIndex("address")); // check for null
              String date = cursor.getString(cursor.getColumnIndex("date")); // convert to date its long
              String message_text = cursor.getString(cursor.getColumnIndex("body"));
              String type = cursor.getString(cursor.getColumnIndex("type")); // check type and get names
  
              // send email from here
              sendSMSEmail(number, date, message_text, type);
          }
      }
      cursor.close();
  }
  </code></pre>