-1

I want to use Intent to send an email without any touching in the screen. I tried the bellow code but it requires to choose many steps: such as email client, send button...I do not want to perform these steps. Just auto send without any touching in the screen. Is it possible in Android M? Thanks

//Email
Intent i = new Intent(Intent.ACTION_SEND);
i.setType("message/rfc822");
i.putExtra(Intent.EXTRA_EMAIL  , new String[]{"abc@gmail.com"});
i.putExtra(Intent.EXTRA_SUBJECT, "Title");
i.putExtra(Intent.EXTRA_TEXT   , "Body");
try {
    startActivity(Intent.createChooser(i, "Send mail..."));
} catch (android.content.ActivityNotFoundException ex) {
    Toast.makeText(this, "There are no email clients installed.", Toast.LENGTH_SHORT).show();
}
John
  • 2,838
  • 7
  • 36
  • 65
  • Check this first http://stackoverflow.com/questions/25136025/sending-mail-in-android-without-intents-using-smtp – Andrey Danilov Mar 06 '17 at 08:46
  • I just want to use intent. Your link use javaxmail – John Mar 06 '17 at 08:52
  • An alternative (better in my opinion) solution would be to have a server side that receives the email data through an HTTP request and then generates/sends the email. – Emanuel Canha Mar 06 '17 at 09:14

1 Answers1

0

using Intent with ACTION_SEND should open all Apps that can handle sending emails and user will have to select one of them to proceed with sending.

Intent intent = new Intent(Intent.ACTION_SENDTO);
intent.setData(Uri.parse("mailto:user_name@provider"));
intent.putExtra(Intent.EXTRA_SUBJECT, "Subject");
intent.putExtra(Intent.EXTRA_TEXT,"Body");
try {
  startActivity(Intent.createChooser(intent, "Send Email"));
} catch (android.content.ActivityNotFoundException ex) {
  Toast.makeText(this, "There are no email clients installed.", Toast.LENGTH_SHORT).show();
}

but if want to send email without using other apps (email clients), you should search for how to send emails directly or check this

Community
  • 1
  • 1
Atef Hares
  • 4,715
  • 3
  • 29
  • 61