1

How can I send an email in android app to a static recipient

<EditText android:id="@+id/from"
            android:drawableStart="@drawable/ic_settings_phone_black_24dp"
            android:drawableLeft="@drawable/ic_settings_phone_black_24dp"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:inputType="number"
            android:ems="10"
            android:hint="From" />
<EditText android:id="@+id/et_subject"
            android:drawableStart="@drawable/ic_settings_phone_black_24dp"
            android:drawableLeft="@drawable/ic_settings_phone_black_24dp"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:inputType="number"
            android:ems="10"
            android:hint="Subject" />
<EditText android:id="@+id/et_message"
            android:drawableStart="@drawable/ic_settings_phone_black_24dp"
            android:drawableLeft="@drawable/ic_settings_phone_black_24dp"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:inputType="number"
            android:ems="10"
            android:hint="message" />

Can you help me please thanks in advance

0

1 Answer 1

0

Use this

    String adress = ((EditText)findViewById(R.id.from)).getText();
    String subject = ((EditText)findViewById(R.id.et_subject)).getText();
    String message = ((EditText)findViewById(R.id.et_message)).getText();

    Intent i = new Intent(Intent.ACTION_SEND);
    i.setType("message/rfc822");
    i.putExtra(Intent.EXTRA_EMAIL  , new String[]{adress});
    i.putExtra(Intent.EXTRA_SUBJECT, subject);
    i.putExtra(Intent.EXTRA_TEXT   , message);
    try {
        startActivity(Intent.createChooser(i, "Send mail..."));
    } catch (android.content.ActivityNotFoundException ex) {
        Toast.makeText(MyActivity.this, "There are no email clients installed.", Toast.LENGTH_SHORT).show();
    }
4
  • thanks but I got this error cannot resolve method 'putExtra(java.lang.String,android.widget.EditText)'
    – Lara Fab
    Jun 15, 2016 at 17:45
  • adress is the sender email? where is the recipient email adress
    – Lara Fab
    Jun 15, 2016 at 17:47
  • Instead of: i.putExtra(Intent.EXTRA_EMAIL , new String[]{adress}); try this: intent.setData(Uri.parse("mailto:[email protected]")); Jun 15, 2016 at 20:46
  • Also, use ACTION_SENDTO instead of ACTION_SEND. Jun 15, 2016 at 20:47

Not the answer you're looking for? Browse other questions tagged or ask your own question.