Search code examples
javaandroidemailjakarta-mail

automated email sending failure


I am using this article to help me send automated emails, but I am having an issue in which nothing seems to be happening and no errors are generated.

I used AsyncTask but it is not sending the mail at all.

public class Sender extends AsyncTask< Void, Void, Void> {

  private Exception exception;

  protected Void doInBackground(String... arg0) {

      Log.v("aws", "OPEN   asa");

      Mail m = new Mail("[email protected]", "password");
      String[] toArr = {"[email protected]"};
      m.setTo(toArr);
      m.setFrom("[email protected]"); 
      m.setSubject("This is an email sent using my Mail JavaMail wrapper from an >Android device."); 
      m.setBody("Email body.");

        try { 
          //m.addAttachment("/sdcard/filelocation"); 

          if(m.send()) { 
              Log.v("aws", "OK SENT");
          } else { 
              Log.v("aws", "NOT SENT");
          } 
        } catch(Exception e) { 
            Log.v("aws", "EXCEPTION . NOT SENT"); 
        }
      return null;
  }

  @Override
  protected Void doInBackground(Void... arg0) {
      // TODO Auto-generated method stub
      return null;
  }

  protected void onPostExecute(Void... arg0) {
      // TODO: check this.exception 
      // TODO: do something with the feed
   }

}

I have used new Sender().execute(); to execute the task, but nothing is happening and no errors are being thrown.

What am I doing wrong?

EDIT

Code has two doInBackground such that second overridden my working doInBackground


Solution

  • Be careful, you have two doInBackground() methods in your code, and the @Override version is what gets executed by the AsyncTask. Just move the code from the wrong doInBackground() version to the right one and delete the wrong one.