/**
* 用于验证登陆是否成功
*/
package action;
import mailutil.GetMail;
import mailutil.SendAttachMail;
import utils.EditorUtils;
public class LoginAction {
private String POP3Host = ""; // POP3服务器
private String SMTPHost = ""; // SMTP服务器
private String user = ""; // 登录服务器的帐号
private String password = ""; // 登录服务器的密码
private GetMail getMail = null;
private SendAttachMail sendMail = null;
// 三个参数的构造方法
public LoginAction(String sMTPHost, String pOP3Host, String user,
String password) {
super();
POP3Host = pOP3Host;
SMTPHost = sMTPHost;
this.user = user;
this.password = password;
// 实例化收邮件对象
getMail = GetMail.getMailInstantiate();
getMail.setPOP3Host(POP3Host);
getMail.setUser(user);
getMail.setPassword(password);
// 实例化发邮件件对象
sendMail = SendAttachMail.getSendMailInstantiate();
sendMail.setSMTPHost(SMTPHost);
sendMail.setUser(user);
sendMail.setPassword(password);
}
// 判断登陆是否成功
public boolean isLogin() {
boolean isLogin = false;
// 判断用户名是否为空
if (checkUser()) {
try {
sendMail.connect();// 连接发件服务器(只能通过连接发件箱验证身份,否者发件时会抛异常)
isLogin = true;
} catch (Exception e) {
isLogin = false;
e.printStackTrace();
}
}
return isLogin;
}
// 验证用户输入数据的有效性
public boolean checkUser() {
boolean check = false;
boolean checkSMTP = SMTPHost.toLowerCase().startsWith("smtp");// 验证smtp服务器
boolean checkPOP = POP3Host.toLowerCase().startsWith("pop");// 验证pop服务器
boolean checkPassword = !"".equals(password) && password.length() >= 1;
boolean checkUser = EditorUtils.checkEmailAdress(user);// 验证邮箱的有效性
if (checkSMTP && checkPOP && checkPassword && checkUser) {
check = true;// 验证通过
}
return check;
}
}
最近下载更多
annazhang LV29
2023年4月7日
微信网友_6191697646571520 LV6
2022年11月24日
伊不归 LV6
2022年4月20日
1029162867 LV13
2021年12月25日
Aoifee LV4
2021年11月11日
linhe27 LV7
2021年3月20日
ming_123_9715 LV23
2021年3月6日
85489354756a LV3
2021年3月6日
gaohd123456789 LV8
2020年12月5日
aataibao LV1
2020年8月16日
最近浏览更多
gao123456789 LV6
2024年2月7日
Wky123456
2023年11月2日
暂无贡献等级
hbsoft2008 LV16
2023年10月19日
EFWAGGFAWGR
2023年10月19日
暂无贡献等级
2036495585 LV9
2023年9月26日
qiqi123456 LV1
2023年9月21日
LongTory LV2
2023年6月6日
dmyafda LV5
2023年3月26日
Tuxxxxx LV3
2023年1月3日
微信网友_6191697646571520 LV6
2022年11月24日

