I am developing a j2me application that sends emails. This is the code I wrote:
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.p开发者_高级运维rintStackTrace();
}
}
}
}
}
I tested this code using WTK 2.5.2_01 and it work perfect and I received the email on my live account, but when deploying the app in my Nokia N70 it doesn't work, and shows this exception:
connection closed by peer *1*
Any ideas?
精彩评论