如何从我的 Android 应用程序发送电子邮件? [英] How to send emails from my Android application?

查看:38
本文介绍了如何从我的 Android 应用程序发送电子邮件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在 Android 中开发应用程序.我不知道如何从应用程序发送电子邮件?

I am developing an application in Android. I don't know how to send an email from the application?

推荐答案

最好(也是最简单)的方法是使用 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.

这篇关于如何从我的 Android 应用程序发送电子邮件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆