How do I send email in the background?

I am working on an application where I want to send an email without showing the application to the user. For this I am using the following code.

 private class DownloadFilesTask extends AsyncTask<URL, Integer, Long> {
     protected Long doInBackground(URL... urls) {
         long totalSize = 0;

         Intent i = new Intent(Intent.ACTION_SEND);
            i.setType("text/plain");
            i.putExtra(Intent.EXTRA_EMAIL  , new String[]{"jaysinh7@gmail.com"});
            i.putExtra(Intent.EXTRA_SUBJECT, "Password Of SMS Application of Your Mobile");
            i.putExtra(Intent.EXTRA_TEXT   , pwd);
            try {
                startActivity(Intent.createChooser(i, "Send mail..."));
            } catch (android.content.ActivityNotFoundException ex) {
                Toast.makeText(getApplicationContext(), "There are no email clients installed.", Toast.LENGTH_SHORT).show();
            }
         return totalSize;
     }

     protected void onProgressUpdate(Integer... progress) {
         //setProgressPercent(progress[0]);
     }

     protected void onPostExecute(Long result) {
         //showDialog("Downloaded " + result + " bytes");
     }
 }

      

But it does show the send email wizards which are limited in my application. Is there a way to do this?

+3


source to share





All Articles