尝试在没有 javamail 的情况下打开 gmail 文件夹
trying to open gmail folders without javamail
所以我创建了一个不使用 javamail 连接 gmail imaps 的程序。我已经成功登录,但我正在努力寻找一种打开文件夹的方法。我已经查看了所有答案都是 java 邮件,我宁愿不使用它,因为我自己学习这个,但是我似乎无法在 java api 中找到任何东西这将允许我在不使用 javamail 的情况下打开此文件。
这是我的代码:
public class CRole {
private BufferedReader socketSIn = null;
private PrintWriter socketSOut = null;
private Socket client;
public CRole(){
SSLSocketFactory sslsocketfactory = (SSLSocketFactory) SSLSocketFactory.getDefault();
try {
client = (SSLSocket) sslsocketfactory.createSocket("imap.gmail.com", 993);
System.out.println("Connect to Host");
}
catch(IOException e) {
System.out.println("Unable to listen on ports");
System.exit(+1);
}
try {
socketSIn = new BufferedReader(new InputStreamReader(client.getInputStream()));
socketSOut = new PrintWriter(client.getOutputStream(), true);
}
catch(IOException e) {
System.out.println("Read failed");
System.exit(+1);
}
}
public void send_connectStringToS(String payload) {
this.socketSOut.println(payload);
}
public String receive_acceptedStringFromS() {
String line = "";
try {
line = this.socketSIn.readLine();
}
catch(IOException e) {
System.out.println("Input/Outpur error.");
System.exit(+1);
}
return line;
}
还有更多代码,但我认为这不是这个问题所必需的。基本上,我必须使用 javamail 还是有其他选择?
还有没有更快的缩进方法,因为当我使用 space bar 时,它总是会避开。
public class Imaps {
private static BufferedReader in = null;
private static PrintWriter out = null;
private static Socket client;
public static void main (String []arg){
SSLSocketFactory sslsocketfactory = (SSLSocketFactory) SSLSocketFactory.getDefault();
try {
client = (SSLSocket) sslsocketfactory.createSocket("imap.gmail.com", 993);
System.out.println("Connect to Host");
}
catch(IOException e) {
System.out.println("Unable to listen on ports");
System.exit(+1);
}
try {
in = new BufferedReader(new InputStreamReader(client.getInputStream()));
out = new PrintWriter(client.getOutputStream(), true);
out.println("abcd CAPABILITY");
String response = (String) in.readLine();
System.out.println("Server: " + response);
out.println("efgh STARTTLS"); //tls part does not work but will not cause any problems being there.
response = (String) in.readLine();
System.out.println("Server: " + response);
String payload3 = "a001 login username @gmail.com password";
out.println(payload3);
response = (String) in.readLine();
System.out.println("Server: " + response);
response = (String) in.readLine();
System.out.println("Server: " + response);
response = (String) in.readLine();
System.out.println("Server: " + response);
//should say success if you enter correct password.
String payload5 = "a002 select inbox";
//String payload5 = "a002 select inbox";
out.println(payload5);
response = (String) in.readLine();
System.out.println("Server: " + response);
response = (String) in.readLine();
System.out.println("Server: " + response);
response = (String) in.readLine();
System.out.println("Server: " + response);
response = (String) in.readLine();
System.out.println("Server: " + response);
}
catch(IOException e) {
System.out.println("Read failed");
System.exit(+1);
}
答案是,当您发送 a002 select 收件箱时,不需要将文件夹存储在打开的任何位置。在此之后,您可以使用 a004 fetch 1 body[text] 请求您想要的任何消息。请注意,第一个将获取您帐户中的第一封电子邮件,而不是最新的。
所以我创建了一个不使用 javamail 连接 gmail imaps 的程序。我已经成功登录,但我正在努力寻找一种打开文件夹的方法。我已经查看了所有答案都是 java 邮件,我宁愿不使用它,因为我自己学习这个,但是我似乎无法在 java api 中找到任何东西这将允许我在不使用 javamail 的情况下打开此文件。
这是我的代码:
public class CRole {
private BufferedReader socketSIn = null;
private PrintWriter socketSOut = null;
private Socket client;
public CRole(){
SSLSocketFactory sslsocketfactory = (SSLSocketFactory) SSLSocketFactory.getDefault();
try {
client = (SSLSocket) sslsocketfactory.createSocket("imap.gmail.com", 993);
System.out.println("Connect to Host");
}
catch(IOException e) {
System.out.println("Unable to listen on ports");
System.exit(+1);
}
try {
socketSIn = new BufferedReader(new InputStreamReader(client.getInputStream()));
socketSOut = new PrintWriter(client.getOutputStream(), true);
}
catch(IOException e) {
System.out.println("Read failed");
System.exit(+1);
}
}
public void send_connectStringToS(String payload) {
this.socketSOut.println(payload);
}
public String receive_acceptedStringFromS() {
String line = "";
try {
line = this.socketSIn.readLine();
}
catch(IOException e) {
System.out.println("Input/Outpur error.");
System.exit(+1);
}
return line;
}
还有更多代码,但我认为这不是这个问题所必需的。基本上,我必须使用 javamail 还是有其他选择?
还有没有更快的缩进方法,因为当我使用 space bar 时,它总是会避开。
public class Imaps {
private static BufferedReader in = null;
private static PrintWriter out = null;
private static Socket client;
public static void main (String []arg){
SSLSocketFactory sslsocketfactory = (SSLSocketFactory) SSLSocketFactory.getDefault();
try {
client = (SSLSocket) sslsocketfactory.createSocket("imap.gmail.com", 993);
System.out.println("Connect to Host");
}
catch(IOException e) {
System.out.println("Unable to listen on ports");
System.exit(+1);
}
try {
in = new BufferedReader(new InputStreamReader(client.getInputStream()));
out = new PrintWriter(client.getOutputStream(), true);
out.println("abcd CAPABILITY");
String response = (String) in.readLine();
System.out.println("Server: " + response);
out.println("efgh STARTTLS"); //tls part does not work but will not cause any problems being there.
response = (String) in.readLine();
System.out.println("Server: " + response);
String payload3 = "a001 login username @gmail.com password";
out.println(payload3);
response = (String) in.readLine();
System.out.println("Server: " + response);
response = (String) in.readLine();
System.out.println("Server: " + response);
response = (String) in.readLine();
System.out.println("Server: " + response);
//should say success if you enter correct password.
String payload5 = "a002 select inbox";
//String payload5 = "a002 select inbox";
out.println(payload5);
response = (String) in.readLine();
System.out.println("Server: " + response);
response = (String) in.readLine();
System.out.println("Server: " + response);
response = (String) in.readLine();
System.out.println("Server: " + response);
response = (String) in.readLine();
System.out.println("Server: " + response);
}
catch(IOException e) {
System.out.println("Read failed");
System.exit(+1);
}
答案是,当您发送 a002 select 收件箱时,不需要将文件夹存储在打开的任何位置。在此之后,您可以使用 a004 fetch 1 body[text] 请求您想要的任何消息。请注意,第一个将获取您帐户中的第一封电子邮件,而不是最新的。