如何采用Android code发送电子邮件发送电子邮件、Android、code

2023-09-06 01:28:18 作者:泪染倾城

可能重复:   Sending电子邮件在Android中使用JavaMail API不使用默认的Andr​​oid应用程序(内建电子邮件应用程序)

我是新来的Andr​​oid编码。我的要求是我想用Android的code发送电子邮件。

I am new to Android Coding. My Requirement is I want to send Email using Android Code.

请指导我关于这个。

推荐答案

下面是解决方案::

Intent i = new Intent(Intent.ACTION_SEND);
i.setType("text/plain");
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();
}