且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何从我的Android应用程序发送电子邮件?

更新时间:2023-10-14 08:45:04

***(也是最简单)的方法是使用Intent:

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.