Adobe Air javascript imap ssl - 无法发出“列表”命令 - 错误的未知命令
我正在 Adobe Air 中编写一个应用程序来从 Gmail 获取电子邮件。我能够使用 SSL 连接并成功登录,但随后我无法继续提取电子邮件。我认为这是因为未维护 SSL 会话。每次我发出命令时,会话都会丢失。
要获取电子邮件,我必须发送登录请求,然后发送 LIST "" "*"
命令。但由于登录后连接中断,当我发送 LIST
命令时,它会作为一个新连接启动,并认为我尚未登录,并给出错误消息 a001 BAD Unknown command gf9if3619638pbc .89
代码如下。有什么想法可以实现这一点,或者这是否可能?
var socket;
function login() {
socket = new air.SecureSocket();
socket.connect('imap.gmail.com', 993);
socket.writeUTFBytes("\n"+"a001 LOGIN username password");
socket.addEventListener(air.ProgressEvent.SOCKET_DATA, socketDataHandler);
}
function fetchEmail() {
socket = new air.SecureSocket();
socket.connect(server, port);
socket.writeUTFBytes("\n"+'a001 LIST "" "*"');
}
I am writing an application in Adobe Air to fetch emails from Gmail. I am able to connect with SSL and successfully login, but then I'm unable to proceed further in fetching emails. I think this is because the SSL session is not maintained. Each time i issue a command, the session is lost.
To fetch email, I have to send a login request and then a LIST "" "*"
command. But since the connection breaks after login, when i send that LIST
command, it starts as a new connection and thinks I haven't logged in, and give the error message a001 BAD Unknown command gf9if3619638pbc.89
The code is below. Any idea to implement this, or is this even possible?
var socket;
function login() {
socket = new air.SecureSocket();
socket.connect('imap.gmail.com', 993);
socket.writeUTFBytes("\n"+"a001 LOGIN username password");
socket.addEventListener(air.ProgressEvent.SOCKET_DATA, socketDataHandler);
}
function fetchEmail() {
socket = new air.SecureSocket();
socket.connect(server, port);
socket.writeUTFBytes("\n"+'a001 LIST "" "*"');
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这并非特定于 SSL/TLS。在这里,当您想要记录时,您将创建一个新连接;当您想要获取电子邮件时,您将创建另一个新连接。就服务器而言,这是两个完全不同的连接。删除
fetchEmail()
中的这些行应该是一个开始:此外,您需要确保在
LOGIN
命令(或任何其他命令实际上),然后再继续执行下一个命令。This is not specific to SSL/TLS. Here, you're creating a new connection when you want to log and another new connection when you want to fetch the e-mails. As far as the server is concerned, these are two completely distinct connections. Removing these lines in
fetchEmail()
should be a start:In addition, you'll need to make sure you get the appropriate response code after the
LOGIN
command (or any other command in fact) before proceeding to the next command.