gpt4 book ai didi

java - 在其他系统上使用 Javamail 连接到 IMAP

转载 作者:行者123 更新时间:2023-12-01 04:32:06 30 4
gpt4 key购买 nike

我在我的项目中使用此代码来连接到 Gmail 的收件箱以及我的 uni 邮件。它在我的系统上运行良好,我可以连接到两者的 IMAP。但一旦在其他系统上尝试相同的代码,Gmail 就会出现连接超时。无法连接。我搜索了一下,发现我的系统正在监听端口 443,而在我测试的其他系统上,它没有监听端口 443。我尝试在其他系统中给出一些入站规则来打开 443 端口,但是一旦我运行我的程序,它就会被阻止。

这个问题是由于端口造成的吗?或者我在这里遗漏了什么?

public class MailConnection {
Folder inbox;

public MailConnection() throws MessagingException{
Properties props = System.getProperties();
props.setProperty("mail.store.protocol", "imap");
try{
Session session = Session.getInstance(props, null);
Store store = session.getStore("imap");
store.connect("mailbox.xyz.com", "emailId@xyz.com", "password");
System.out.println(store);

inbox = store.getFolder("Inbox");
System.out.println("No of Unread Messages : " + inbox.getUnreadMessageCount());
}
catch (NoSuchProviderException e){
e.printStackTrace();
System.exit(1);
}
}

最佳答案

您正在连接到非 SSL IMAP 端口 - 143。我不知道“443”来自哪里。

Gmail 需要 SSL IMAP 端口。请参阅this JavaMail FAQ entry举个例子。

如果不起作用,请参阅these debugging tips .

关于java - 在其他系统上使用 Javamail 连接到 IMAP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17873767/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com