2

I have following condition: enter image description here

How do I send email to example@mail.com on submitButton clicklistener ?

submitButton.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            //how to send email ??

        }
    });

Help !

Alex Lockwood
  • 83,063
  • 39
  • 206
  • 250
captaindroid
  • 2,868
  • 6
  • 31
  • 45
  • See similar question [here](http://stackoverflow.com/questions/2197741/how-to-send-email-from-my-android-application) – EdChum Mar 23 '12 at 00:18
  • duplicate http://stackoverflow.com/questions/2197741/how-to-send-email-from-my-android-application ? – John Leehey Mar 23 '12 at 00:19
  • There is only three field recipient email address, subject of email and body of email. When i add above fields such as name, sender email address, did it create any problem ? – captaindroid Mar 23 '12 at 00:28

1 Answers1

4

Its very simple. In your onClick method simply create and populate the following Intent

Intent i = new Intent(android.content.Intent.ACTION_SEND);
i.setType("text/plain");
i.putExtra(Intent.EXTRA_EMAIL  , new String[]{"recipient@example.com"});
i.putExtra(Intent.EXTRA_SUBJECT, "subject");
i.putExtra(Intent.EXTRA_TEXT   , "body");
startActivity(Intent.createChooser(i, "Email:"));
Alex Lockwood
  • 83,063
  • 39
  • 206
  • 250
slayton
  • 20,123
  • 10
  • 60
  • 89
  • Can i add sender emailaddress like `emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, senderEmailAddress); emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, senderName); ` to this ?? – captaindroid Mar 23 '12 at 00:33
  • NO! because `android.content.intent.EXTRA_SUBJECT` specifies the **Subject** of the email – slayton Mar 23 '12 at 00:34
  • If you want to specify the name and email address of the recipient you could try using a string like such: `"John Smith "`. I haven't tried it so I don't know if it works, but it should only take you a few seconds to try and see if it works – slayton Mar 23 '12 at 00:35
  • Thanx buddies,now I get it, i will try my best, if any problem, i will report to u guys. – captaindroid Mar 23 '12 at 00:47
  • Cant i directly send mail by clicking submit button only without opening default mail client ? – captaindroid Mar 23 '12 at 18:30
  • @captainpirate http://stackoverflow.com/questions/2020088/sending-email-in-android-using-javamail-api-without-using-the-default-android-a – slayton Mar 23 '12 at 19:07
  • from the refrence u given, i am able to send mail without launching built mail application of android by clicking send button.**But i have to provide gmail authientciation there, can't i remove that part ??** or there any way to fetch gmail username and password from default gmail app ?? – captaindroid Mar 24 '12 at 08:04
  • If you don't have access to the gmail credentials then you'll have to provide credentials for "some" account, and NO you can't retrieve them without the users approval. – slayton Mar 24 '12 at 13:31
  • Why not use web form instead of an email? – slayton Mar 24 '12 at 13:31
  • dont have any idea about web form ?? can u reference me to some good tuts ? – captaindroid Mar 24 '12 at 16:55