2

I just started with Android development and my first project is to create app for packing and moving company. I've created the form and wanted to send data to the email of an employee. I used this code:

Intent i = new Intent(Intent.ACTION_SEND);
i.setData(Uri.parse("email"));
String[] s={"abc@gmail.com","xyz@gmail.com"};
i.putExtra(Intent.EXTRA_EMAIL,s);
i.putExtra(Intent.EXTRA_SUBJECT,"This is a Subject");
i.putExtra(Intent.EXTRA_TEXT,"Hii This is the Email Body");
i.setType("message/rfc822");
Intent chooser = Intent.createChooser(i,"Launch Email");
startActivity(chooser);

But the problem is user is prompted with option gmail and email and at last he/she also needs to click on send button. But I don't want that. Instead I want the data to be sent without any prompt. Please help!

Dat Nguyen
  • 1,626
  • 22
  • 25
Paramjeet Singh
  • 2,930
  • 2
  • 9
  • 17
  • Please follow the link you can send with out any prompt https://stackoverflow.com/questions/2020088/sending-email-in-android-using-javamail-api-without-using-the-default-built-in-a/2033124#2033124 – Rajasekhar Jun 09 '17 at 03:59

1 Answers1

4

GmailBackground is small library to send an email in background without user interaction :

Usage:

    BackgroundMail.newBuilder(this)
            .withUsername("username@gmail.com")
            .withPassword("password12345")
            .withMailto("toemail@gmail.com")
            .withType(BackgroundMail.TYPE_PLAIN)
            .withSubject("this is the subject")
            .withBody("this is the body")
            .withOnSuccessCallback(new BackgroundMail.OnSuccessCallback() {
                @Override
                public void onSuccess() {
                    //do some magic
                }
            })
            .withOnFailCallback(new BackgroundMail.OnFailCallback() {
                @Override
                public void onFail() {
                    //do some magic
                }
            })
            .send();

Source

(I've tested it myself)

S.R
  • 2,819
  • 2
  • 22
  • 49
  • I tried it but email was not sent and i got an email as follow Google just blocked someone from signing into your Google account xxxxxxxxx@gmail.com from an app that may put your account at risk – Paramjeet Singh Jun 09 '17 at 10:18
  • make sure you set `withUsername` and `withPassword` right, there should be no problem, I used it in one of my projects without any issue. However, if you still had this problem after making sure your inputs are right, then try another library. – S.R Jun 09 '17 at 11:01