Play Framework 1.2.3 (获取邮箱发送密码到邮箱)

public static void findpsw(){

render();

}

public static void getemail(String username){

String msg = "";

if(username == null || username.equals("")){

JsonObjectUtil jso = new JsonObjectUtil();

msg = "用户名不能为空";

jso.setMsg(msg);

jso.setUsername(username);

renderJSON(jso);

}

username = username.trim();

if(Application.isCheckUserName(username)){

List<Company> list = Company.q().filter("username", username).asList();

Company company = list.get(0);

JsonObjectUtil jso = new JsonObjectUtil();

String email = company.email;

int regindex = email.indexOf("@");

String subemail = email.substring(1, regindex-1);

String strto = "";

for(int i = 0; i < subemail.length() ; i++){

strto += "x";

}

String target = CommonUtils.replace(email, subemail, strto);

jso.setEmail(target);

renderJSON(jso);

}else{

JsonObjectUtil jso = new JsonObjectUtil();

msg = "用户名不存在";

jso.setMsg(msg);

jso.setUsername(username);

renderJSON(jso);

}

}

public static void sendemail(String username,String email){

String msg = "";

if(username == null || username.equals("")){

JsonObjectUtil jso = new JsonObjectUtil();

msg = "用户名不能为空";

jso.setMsg(msg);

jso.setUsername(username);

renderJSON(jso);

}

if(email == null || email.equals("")){

JsonObjectUtil jso = new JsonObjectUtil();

msg = "邮箱不能为空";

jso.setMsg(msg);

jso.setUsername(username);

jso.setEmail(email);

renderJSON(jso);

}else{

if(!CommonUtils.checkEmail(email)){

JsonObjectUtil jso = new JsonObjectUtil();

msg = "邮箱输入不合法";

jso.setMsg(msg);

jso.setUsername(username);

jso.setEmail(email);

renderJSON(jso);

}

}

username = username.trim();

email = email.trim();

List<Company> list = Company.q().filter("username", username).asList();

Company company = list.get(0);

if (email.equals(company.email)) {

StringBuffer sb = new StringBuffer();

sb.append("<html>");

sb.append("<head>");

sb.append("</head>");

sb.append("<body>");

sb.append("<div style=\"height:300px;width:460px;border:6px solid #ccc;font-family:微软雅黑;font-size:14px;\">");

sb.append("<div style=\"height:72px; background:#5E5E5E;font-family: 微软雅黑; color: white;font-size: 36px;font-style: italic;font-variant: normal;\"><div style=\" padding-top:10px;padding-left:12px;\">名片碰碰</div></div>");

sb.append("<ul>");

sb.append("<li style=\"margin-top:20px; width:360px; list-style:none;\">").append("亲爱的<span>").append(username).append("</span></li>");

sb.append("<li style=\"margin-top:20px; width:360px; list-style:none;\">").append("您的密码是").append(company.password+"</li>").append("请点击下面链接进行登录");

sb.append("<li style=\"margin-top:20px; width:360px; list-style:none;\"><a href=\"http://192.168.1.136:9000/application/login\">http://192.168.1.136:9000/application/login</a></li>");

sb.append("<li style=\"margin-top:20px; width:360px; list-style:none;\"><a href=\"www.peng.me.com\">www.peng.me.com</a></li>");

sb.append("</ul>");

sb.append("</div>");

sb.append("</body>");

sb.append("</html>");

String regemail = email.substring(email.indexOf("@"), email.length());

MailSenderInfo mailInfo = new MailSenderInfo();

if(regemail.equals("@163.com")){

mailInfo.setMailServerHost("smtp.163.com");  

mailInfo.setMailServerPort("25");

mailInfo.setValidate(true);

}

//else if(regemail.equals("@gmail.com")){

//mailInfo.setMailServerHost("smtp.gmail.com"); 

//mailInfo.setMailServerPort("465");

//mailInfo.setValidate(true);

//}

else{

mailInfo.setMailServerHost("smtp.exmail.qq.com");

mailInfo.setMailServerPort("25");

mailInfo.setValidate(true);

}

mailInfo.setUserName("[email protected]");

mailInfo.setPassword("raycool123456");// 您的邮箱密码

mailInfo.setFromAddress("[email protected]");

mailInfo.setToAddress(email);

mailInfo.setSubject("名片碰碰获取密码");

mailInfo.setContent(sb.toString());

//mailInfo.setContent(username +"您好,您的密码是 " + company.password);

// 这个类主要来发送邮件

SimpleMailSender sms = new SimpleMailSender();

// sms.sendTextMail(mailInfo);//发送文体格式

JsonObjectUtil jso = new JsonObjectUtil();

jso.setUsername(username);

if(sms.sendHtmlMail(mailInfo)){

msg = "密码已发送至您的邮箱,请查收邮件";

jso.setMsg(msg);

jso.setEmail(email);

renderJSON(jso);

}else{

msg = "邮件发送失败!";

jso.setMsg(msg);

jso.setEmail(email);

renderJSON(jso);

}


} else{

JsonObjectUtil jso = new JsonObjectUtil();

msg = "邮箱输入错误请重新输入";

jso.setMsg(msg);

jso.setUsername(username);

jso.setEmail(email);

renderJSON(jso);

}

}


Play Framework 1.2.3 (获取邮箱发送密码到邮箱)


转载于:https://my.oschina.net/cpy/blog/485157