提问人:Yitbarek 提问时间:12/17/2021 最后编辑:Yitbarek 更新时间:12/17/2021 访问量:82
如何使用 J2Me MIDLET 发送电子邮件
how can i send email using j2me midlet
问:
大家好,我一直在尝试编写 J2me 电子邮件客户端代码,使 midlet 能够将电子邮件发送到我的帐户,但我遇到了以下错误“必须先发出 STARTTLS 命令” 这是代码,我包含了模拟器上显示的结果和图像 我从 [Oracle Java ME 网站][1] 获得了起始源代码
try {
//smtpServerAddress=smtp.gmail.com
sc = (SocketConnection)Connector.open("socket://"+smtpServerAddress+":587");
is = sc.openInputStream();
os = sc.openOutputStream();
os.write(("HELO there" + "\r\n").getBytes());
os.write(("MAIL FROM: "+ from +"\r\n").getBytes());
os.write(("RCPT TO: "+ to + "\r\n").getBytes());
os.write("DATA\r\n".getBytes());
os.write(("From: "+from+"\r\n").getBytes());
os.write(("To: "+to+"\r\n").getBytes());
os.write(("Subject: "+subject+"\r\n").getBytes());
os.write((msg+"\r\n").getBytes()); // message body
os.write(".\r\n".getBytes());
os.write("QUIT\r\n".getBytes());
// debug
StringBuffer sb = new StringBuffer();
int c = 0;
while (((c = is.read()) != -1) ) {
sb.append((char) c);
}
si.setText("SMTP server response - " + sb.toString());
} catch(IOException e) {}```
[the image shows the output result on emulator][2]
[1]: https://www.oracle.com/technical-resources/articles/javame/lowlevel-networkprogramming-midp20.html
[2]: https://i.stack.imgur.com/YJ0Y0.png
答: 暂无答案
评论