電子メールを送信する 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 を使用してこのコードをテストしたところ、完全に機能し、ライブ アカウントでメールを受信しましたが、Nokia N70 にアプリを展開すると機能せず、次の例外が表示されます。
connection closed by peer *1*
何か案は?