title: How to send email in android using javamail API
body: <p>I want to send an email in android app without using email client(without user interaction). I have code and I tried it in my app. But when I tried to run, it showed a notification "Message sent". But I did not receive any email from the particular id which I mentioned in the code. I did not get any error or warnings too. Please anyone help me to get out of this problem. Thanks</p>
  
  <p><strong>Here is my code</strong></p>
  
  <pre><code>    //Import files
  
      public class SendReport extends ActionBarActivity implements View.OnClickListener {
  
      Button button;
      EditText editText, editText2;
      String recipient;
      Session session = null;
      ProgressDialog pdialog = null;
      Context context = null;
      String textmessage = null;
      String username = "sender@gmail.com";
      String password = "senderpassword";
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_send_report);
          context = this;
          button = (Button) findViewById(R.id.sendbutton);
          editText = (EditText) findViewById(R.id.textView2);
          editText2 = (EditText) findViewById(R.id.textView4);
          button.setOnClickListener(this);
          }
  
      @Override
      public void onClick(View v) {
          recipient = editText.getText().toString();
          textmessage = editText2.getText().toString();
  
          Properties props = new Properties();
          props.put("mail.smtp.auth", "true");
          props.put("mail.smtp.starttls.enable", "true");
          props.put("mail.smtp.host", "smtp.gmail.com");
          props.put("mail.smtp.port", "587");
          session = Session.getDefaultInstance(props, new javax.mail.Authenticator() {
              protected PasswordAuthentication getPasswordAuthentication() {
                  return new PasswordAuthentication(username,password);
              }
          });
          pdialog = ProgressDialog.show(context, "", "Sending Mail...", true);
          RetrieveFeedTask task = new RetrieveFeedTask();
          task.execute();
      }
  
   class RetrieveFeedTask extends AsyncTask&lt;String, Void, String&gt; {
  
         protected String doInBackground(String... params) {
  
             try
             {
  
                 MimeMessage message = new MimeMessage(session);
                 message.setFrom(new InternetAddress("anithabadhu@gmail.com"));
                 message.setRecipients(javax.mail.Message.RecipientType.TO, InternetAddress.parse(recipient));
                 message.setContent(textmessage,"text/html; charset=utf-8");
                 Transport.send(message);
             }
  
             catch(MessagingException e)
             {
                 e.printStackTrace();
             }
  
             catch(Exception e)
             {
                 e.printStackTrace();
             }
  
             return null;
         }
          protected void onPostExecute(String feed) {
                pdialog.dismiss();
                editText2.setText("");
                editText.setText("");
                Toast.makeText(getApplicationContext(), "Message sent", Toast.LENGTH_SHORT).show();
          }
      }
  </code></pre>