android email

一:最基本的发送邮件
Intent data=new Intent(Intent.ACTION_SENDTO);
data.setData(Uri.parse("mailto:1213244340@qq.com")); 
data.putExtra(Intent.EXTRA_SUBJECT, "这是标题"); 
data.putExtra(Intent.EXTRA_TEXT, "这是内容");  
startActivity(data); 

二:发送给多人以及抄送和密送都很简单,查找Intent类中的Extra常量,发送有这么三个常量:Intent.EXTRA_EMAIL,Intent.EXTRA_CC,Intent.EXTRA_BCC。这三个分别用于传递“接受人地址列表”、“抄送人地址列表”和“密送人地址列表”,传递的都是String[]类型的Email地址,如果数组中有多个地址,就可以发送给多人
Intent data=new Intent(Intent.ACTION_SENDTO);
data.setData(Uri.parse("mailto:1213244340@qq.com"));
data.putExtra(Intent.EXTRA_EMAIL, new String[]{"222@qq.com","333@qq.com"}); 
data.putExtra(Intent.EXTRA_CC, new String[]{"111@qq.com"});
data.putExtra(Intent.EXTRA_BCC, new String[]{"111@qq.com"});
data.putExtra(Intent.EXTRA_SUBJECT, "这是标题");
data.putExtra(Intent.EXTRA_TEXT, "这是内容");
startActivity(data);  

三:发送带附件的邮件
//只启动邮件发送方式
Uri uri = Uri.parse("mailto:");
Intent intent = new Intent(Intent.ACTION_SENDTO,uri);
intent.putExtra(Intent.EXTRA_SUBJECT, "邮件标题");
intent.putExtra(Intent.EXTRA_STREAM,Uri.parse("file:///"+Environment.getExternalStorageDirectory()+ File.separator + "附件目录"));
startActivity(intent);


//启动多种发送方式(可以选择邮件方式)
File file = new File("\sdcard\android123.cwj"); //附件文件地址
Intent intent = new Intent(Intent.ACTION_SEND);
 intent.putExtra("subject", file.getName()); //
 intent.putExtra("body", "android123 - email sender"); //正文
 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客户端进行发送
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值