我如何发送电子邮件从我的Andr​​oid应用程序?我的、应用程序、发送电子邮件、Andr

2023-09-11 23:53:22 作者:癡人說夢i

我写为Android应用程序。我怎样才能从它发送电子邮件?

I am writing an application for Android. How can I send an email from it?

推荐答案

最好的(和最简单的)方法是使用一个意图

The best (and easiest) way is to use an Intent:

Intent i = new Intent(Intent.ACTION_SEND);
i.setType("message/rfc822");
i.putExtra(Intent.EXTRA_EMAIL  , new String[]{"recipient@example.com"});
i.putExtra(Intent.EXTRA_SUBJECT, "subject of email");
i.putExtra(Intent.EXTRA_TEXT   , "body of email");
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();
}

否则,你就必须编写自己的客户端。

Otherwise you'll have to write your own client.