Android调用本地邮箱app
/**
* 正则表达式:验证邮箱
*/
public static final String REGEX_EMAIL = "^([a-z0-9A-Z]+[-|\.]?)+[a-z0-9A-Z]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\.)+[a-zA-Z]{2,}$";
@Event(R.id.btn_send)
private void sendEmail(View view){
String addressee = edt_addressee.getText().toString();
String content = edt_content.getText().toString();
String title = edt_title.getText().toString();
if (TextUtils.isEmpty(addressee)){
Toast.makeText(this,"收件人地址不能为空",Toast.LENGTH_SHORT).show();
return;
}
if(!isEmail(addressee)){
Toast.makeText(this,"请输入正确的邮箱地址",Toast.LENGTH_SHORT).show();
return;
}
if (TextUtils.isEmpty(content)){
Toast.makeText(this,"内容不能为空",Toast.LENGTH_SHORT).show();
return;
}
if (TextUtils.isEmpty(title)){
Toast.makeText(this,"标题不能为空",Toast.LENGTH_SHORT).show();
return;
}
// 必须明确使用mailto前缀来修饰邮件地址,如果使用
Uri uri = Uri.parse("mailto:"+addressee);
String[] email = {addressee};
Intent intent = new Intent(Intent.ACTION_SENDTO, uri);
intent.putExtra(Intent.EXTRA_EMAIL, email);//结果将匹配不到任何应用
intent.putExtra(Intent.EXTRA_CC, email); // 抄送人
intent.putExtra(Intent.EXTRA_SUBJECT, title); // 主题
intent.putExtra(Intent.EXTRA_TEXT, content); // 正文
startActivity(Intent.createChooser(intent, "请选择邮件类应用"));
}
/**
* 校验邮箱
*
* @param email
* @return 校验通过返回true,否则返回false
*/
public static boolean isEmail(String email) {
return Pattern.matches(REGEX_EMAIL, email);
}