Rajeev
Rajeev

Reputation: 46929

Android send mail

In the following main.xml i have a edittext,my question is how to onclick of send mail button how to send a mail where the To address is hardcoded always..

 mail.setOnClickListener(

        @Override
        public void onClick(View v) {
       //How to sendmail to adress [email protected] oblibk of send mail button

    });

     <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:id="@+id/linearLayout3" android:layout_width="fill_parent" android:layout_height="fill_parent">
      <EditText android:id="@+id/editText2" android:layout_width="fill_parent" android:layout_height="wrap_content">
         <requestFocus></requestFocus>
      </EditText>
      <Button android:text="Send Mail" android:id="@+id/mail" android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>
      <Button android:text="Back" android:id="@+id/back2" android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>


   </LinearLayout>

Upvotes: 1

Views: 792

Answers (1)

kameny
kameny

Reputation: 2370

 final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);     
emailIntent.setType("plain/text");     
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{"[email protected]"});     
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, yourSubject);     
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, yourBodyText);     
context.startActivity(Intent.createChooser(intent, "Send mail..."));

Upvotes: 5

Related Questions