如何在Android应用程序中发送电子邮件?

时间:2016-06-15 17:14:55

标签: android

如何在Android应用中向静态收件人发送电子邮件

<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" />
你能帮帮我吗? 提前谢谢

1 个答案:

答案 0 :(得分:0)

使用此

    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();
    }