【发布时间】:2011-12-05 21:36:59
【问题描述】:
我已经看到了其他问题,但我想要一些不同且更简单的东西(我认为)。
我有一个活动,点击发送到您使用 java 邮件 api 输入欢迎电子邮件的电子邮件地址。更具体地说,当它第一次运行时,您输入您的 gmail 帐户以及您的密码和欢迎电子邮件的发送地址。现在,当我输入错误的密码时,会创建一个异常,并且您要求输入您的真实密码或用户名。但如果我把我的真正的它要求我再次这样做。此外,如果我把我的真实的,然后它会继续发送欢迎邮件。我怎样才能解决这个问题?这是一个示例代码:
EmailValidator val = new EmailValidator();
Boolean a = val.validate(yemail);
Boolean b = val.validate(temail);
if (a == false || b == false){
AlertDialog.Builder box = new AlertDialog.Builder(this);
// Set the message to display
box.setMessage("Please enter a valid email address!");
// Add a neutral button to the alert box and assign a click listener
box.setNeutralButton("Ok", new DialogInterface.OnClickListener() {
// Click listener on the neutral button of alert box
public void onClick(DialogInterface arg0, int arg1) {
Toast.makeText(getApplicationContext(), "OK", Toast.LENGTH_LONG).show();
}
});
box.show();
}// end if validating emails
if (a == true && b == true && ypass != null){
try { // send mail
GmailSender sender = new GmailSender(yemail,ypass); // SUBSTITUTE HERE
sender.sendMail(
"EMERGENCY", //subject.getText().toString(),
"hi", //body.getText().toString(),
"stathias7@hotmail.com", //from.getText().toString(),
temail //to.getText().toString() address where the mail is sent to
);
}
catch (Exception e) {
AlertDialog.Builder box = new AlertDialog.Builder(this);
// Set the message to display
box.setMessage("Please Re-enter your Gmail username and pasword");
// Add a neutral button to the alert box and assign a click listener
box.setNeutralButton("Ok", new DialogInterface.OnClickListener() {
// Click listener on the neutral button of alert box
public void onClick(DialogInterface arg0, int arg1) {
Toast.makeText(getApplicationContext(), "OK", Toast.LENGTH_LONG).show();
}
});
box.show();
} // end catching Exception
} // try to send mail
}
【问题讨论】: