0

I have an app that needs to send email without user interaction. I've developed this code that set the default email client as GMAIL, but is necessary press SEND.

Intent emailIntent = new Intent(Intent.ACTION_SENDTO);
    emailIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    emailIntent.setType("plain/text");
    emailIntent.setClassName("com.google.android.gm", "com.google.android.gm.ComposeActivityGmail");
    emailIntent.setData(Uri.parse("mailto:"));
    emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{"user@mail.com"});
    emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "SUBJECT TEXT");
    emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "body text");
    startActivity(emailIntent);

After that, it will show the email form with fields filled and the user needs to press SEND button. Does someone know how to send automatically ?

Gmail client waiting for user action to press SEND button

Edimar Martins
  • 2,631
  • 1
  • 9
  • 10

1 Answers1

0

You can do this by java mail api.

For that you have to add some jar files.

You have to follow this link because it worked for me.

http://www.javatpoint.com/example-of-sending-email-using-java-mail-api

Kishan
  • 39
  • 4
  • Thanks... I got it !! I've downloaded the files, renamed from .zip to .jar, I added in my project. I follow the example here and it WORKS ! http://stackoverflow.com/questions/2020088/sending-email-in-android-using-javamail-api-without-using-the-default-built-in-a – Edimar Martins Mar 02 '17 at 19:39