gpt4 book ai didi

java - 无法连接到我的邮件服务器(java)

转载 作者:行者123 更新时间:2023-12-01 15:55:10 25 4
gpt4 key购买 nike

public class ConnectGmail {

public static void main(String args[]) throws Exception {


PasswordAuthentication authentication;

Properties props = System.getProperties();
props.setProperty("mail.store.protocol", "imap");

Session session = Session.getDefaultInstance(props);
Store store = session.getStore("imap");

try {

store.connect(host , user , "password");
} catch (Exception e) {
e.printStackTrace();
}
}
}

收到此错误..我几乎尝试了所有协议(protocol)

javax.mail.MessagingException: Connection refused: connect;
nested exception is:
java.net.ConnectException: Connection refused: connect
at com.sun.mail.imap.IMAPStore.protocolConnect(IMAPStore.java:571)
at javax.mail.Service.connect(Service.java:288)
at javax.mail.Service.connect(Service.java:169)
at ConnectGmail.main(ConnectGmail.java:26)

有什么帮助吗?

最佳答案

您需要先启用邮件验证才能使用:

将属性 mail.smtp.auth 设置为 true 以启用身份验证。

If true, attempt to authenticate the user using the AUTH command. Defaults to false.

@查看 com.sun.mail.smtp 包的 Javadoc

关于java - 无法连接到我的邮件服务器(java),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5230252/

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