Sending Mail in Android Intent Without Pressing Send Button

306 views Asked by At

i was creating Android Intent Mail. i am getting all the subject, to , mail body in email. is there is any possibility to send the mail without pressing send button . enter image description here

My code is :

 public void Sendmail(HashMap s) {

        HashMap<String, String> sss = s;

        String[] toppings = new String[sss.size()];

        int size1 = 0;

        for (String key : sss.keySet()) {

            toppings[size1] = key + "\n" + sss.get(key) + "\n";
            System.out.println("key: " + key + " value: " + sss.get(key));


            size1++;
        }

        StringBuilder builder = new StringBuilder();
        for (String s3 : toppings) {
            builder.append(s3);
        }
        String mbody = builder.toString();


        Intent i = new Intent(android.content.Intent.ACTION_SEND);
        i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        i.setType("plain/text");

        i.putExtra(android.content.Intent.EXTRA_SUBJECT, "Task Activity");
        i.putExtra(android.content.Intent.EXTRA_TEXT, mbody);
        i.putExtra(android.content.Intent.EXTRA_EMAIL, new String[] {"[email protected]"});

        try {
            startActivity(i);
        } catch (android.content.ActivityNotFoundException ex) {
            Toast.makeText(Main2Activity.this, "There are no email clients installed.", Toast.LENGTH_SHORT).show();
        }


    }
2

There are 2 answers

3
Jogendra Anipr On

You can't do it. A user should know what he is sending. Also a user should be aware about his actions.

You can do it using API and sending Email from server.

0
Gopal On

You can't do it with Share Intent of Android as it will populate installed app from your device which can process your data.

You can achieve this by following ways:

  1. Implement mail client to send emails from your server side. ex: mailgun.
  2. Integrate API's like Javamail or Gmail to your android app to get your work done.