-4

Possible Duplicate:
How to send email from my Android application?

I am creating an main.xml

How to send Email in android. But mandatory is TO is fixed id (ex: To:myid@example.com)

I have main.xml

   <LinearLayout android:id="@+id/LinearLayout02"
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"     
   android:orientation="horizontal">

    <TextView android:layout_width="wrap_content"
     android:layout_height="wrap_content" 
     android:id="@+id/to"
     android:text="To" />

    <EditText android:layout_width="wrap_content"
    android:layout_height="wrap_content" 
    android:width="170dip" 
    android:id="@+id/to" />
    </LinearLayout>

   <LinearLayout android:id="@+id/LinearLayout02"
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"     
   android:orientation="horizontal">

   <TextView android:layout_width="wrap_content"
     android:layout_height="wrap_content" 
     android:id="@+id/form"
     android:text="from" />

   <EditText android:layout_width="wrap_content"
    android:layout_height="wrap_content" 
    android:width="170dip" 
    android:id="@+id/emailaddress" />

</LinearLayout>

<LinearLayout android:id="@+id/LinearLayout03"
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content"     
     android:orientation="horizontal">

 <TextView android:layout_width="wrap_content"     
       android:layout_height="wrap_content" 
       android:id="@+id/emailsubject"     
       android:text="Subject" />
   <EditText android:layout_width="wrap_content"
     android:layout_height="wrap_content" 
     android:width="170dip" 
     android:id="@+id/emailsubject" />
</LinearLayout>

<EditText android:layout_width="wrap_content"
    android:layout_height="wrap_content" 
    android:lines="5" 
    android:width="300dip"
    android:hint="Compose Mail"
    android:id="@+id/emailtext" />

<Button android:layout_width="wrap_content" 
    android:layout_height="wrap_content"
    android:id="@+id/emailsen" 
    android:text="send"
    android:width="150dip" />
</LinearLayout>
Community
  • 1
  • 1
Kumar
  • 623
  • 3
  • 6
  • 16

2 Answers2

3

This is intent to use to send the email

Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
        emailIntent.setType("plain/text");
        String msg = "MESSAGE TEXT HEAR";
        emailIntent.putExtra(Intent.EXTRA_EMAIL,
                new String[] { "myid@gmail.com" });
        emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,
                "SUBJECT TEXT HEAR");
        emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, msg);
        startActivity(Intent.createChooser(emailIntent, "Send mail..."));
Ashish Dwivedi
  • 8,048
  • 5
  • 58
  • 78
1

It is possible by using an Intent like:

   intent.putExtra(Intent.EXTRA_EMAIL, new String[] { "username@domain.com" });
thampi joseph
  • 700
  • 1
  • 8
  • 20
  • Not a good answer at all. – Egor Jan 17 '13 at 11:19
  • 1
    Can't we do it by using an intent Mr. Egor? We can do it by saying a particular mail-ID like : intent.putExtra(Intent.EXTRA_EMAIL, new String[] { "username@domain.com" }); Can't we use like this? – thampi joseph Jan 17 '13 at 12:08
  • You're absolutely right, we can do it using an Intent. But just stating this is not nearly enough to help anyone with his problem. You should describe the solution, providing a code example or a link to some helpful information. – Egor Jan 17 '13 at 12:18