我正在开发一个发送电子邮件的 j2me 应用程序。这是我写的代码:
public class SendMail extends MIDlet implements CommandListener {
SmtpClient smtpClient = null;
Form form=null;
Command cmdSend=null;
Command cmdExit=null;
protected void startApp() throws MIDletStateChangeException {
form = new Form("Send Email");
cmdSend = new Command("Send", Command.OK, 0);
cmdExit = new Command("Exit", Command.EXIT, 0);
form.addCommand(cmdExit);
form.addCommand(cmdSend);
form.setCommandListener(this);
Display.getDisplay(this).setCurrent(form);
}
protected void pauseApp() {
}
protected void destroyApp(boolean unconditional) throws MIDletStateChangeException {
notifyDestroyed();
}
public void commandAction(Command c, Displayable d) {
if (d == form) {
if (c == cmdSend) {
new Thread(new Runnable() {
public void run() {
try {
Message message = new Message("****@gmx.com", "****@live.com", "Test my j2me app");
message.addBodyLine("Hi this is a test email by me");
smtpClient = new SmtpClient("http://127.0.0.1/");
smtpClient.open("mail.gmx.com", 587, false, "****@gmx.com", "myPassword");
smtpClient.sendMessage(message);
smtpClient.close();
} catch (IOException ex) {
ex.printStackTrace();
form.append(ex.getMessage()+ "*1*");
} catch (MailException ex) {
ex.printStackTrace();
form.append(ex.getMessage() + "*2*");
}
}
}).start();
} else if (c == cmdExit) {
try {
destroyApp(true);
} catch (MIDletStateChangeException ex) {
ex.printStackTrace();
}
}
}
}
}
我使用 WTK 2.5.2_01 测试了这段代码,它运行良好,我在我的真实帐户上收到了电子邮件,但是在我的诺基亚 N70 中部署应用程序时它不起作用,并显示此异常:
connection closed by peer *1*
有任何想法吗?