Androidの发送Email
16lz
2022-06-11
Android发送Email的两种方法:
方法一:通过Intent调用内置的Gmail发送邮件
优点:简单、方便
方法一:通过Intent调用内置的Gmail发送邮件
优点:简单、方便
缺点:缺少灵活性,只能使用关联的gmail发送邮件
//收件人地址,如果多个人时候,中间添加逗号隔开。Uri uri = Uri.parse("mailto:g@huaqin.com,xia@huaqin.com"); Intent emailIntent = new Intent(Intent.ACTION_SENDTO,uri); emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,"邮件发送主题"); //邮件地址emailIntent.putExtra(android.content.Intent.EXTRA_TEXT,"邮件发送内容"); //邮件内容startActivity(emailIntent);
或者
String[] recipients = { "guwe@huaqin.com","xia@huaqin.com" };Intent intent = new Intent();intent.setType("plain/text");intent.setAction(Intent.ACTION_SEND);intent.putExtra(Intent.EXTRA_EMAIL, recipients);intent.putExtra(Intent.EXTRA_SUBJECT, "邮件主题");intent.putExtra(Intent.EXTRA_TEXT, "邮件内容");startActivity(Intent.createChooser(intent, "Sending..."));
通过Intent发送电子邮件含附件
Intent intent = new Intent(Intent.ACTION_SEND);intent.putExtra("subject", "邮件主题"); intent.putExtra("body", "邮件内容");intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file)); //添加附件,附件为file对象if (file.getName().endsWith(".gz")) { intent.setType("application/x-gzip"); //如果是gz使用gzip的mime} else if (file.getName().endsWith(".txt")) { intent.setType("text/plain"); //纯文本则用text/plain的mime} else { intent.setType("application/octet-stream"); //其他的均使用流当做二进制数据来发送}startActivity(intent); //调用系统的mail客户端进行发送
更多相关文章
- Android实现动态显示或隐藏密码输入框的内容
- Android(安卓)循环ListView
- [android]控件EditText常用属性
- android解析httpresponce内容
- Android使用文件管理器打开指定文件夹,浏览里面的内容
- Android强制使用WebView不调用系统或外部浏览器
- Android心得3.2--用SAX解析器解析xml文件内容
- ListPreference之entries和entryValues
- android2.0+通讯簿查询详解