无法连接到我的邮件服务器(java) [英] Unable to connect to my mail Server (java)
本文介绍了无法连接到我的邮件服务器(java)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
属性props = System.getProperties();
props.setProperty(mail.store.protocol,imap);
会话session = Session.getDefaultInstance(props);
Store store = session.getStore(imap);
尝试{
store.connect(host,user,password);
} catch(Exception e){
e.printStackTrace();
}
}
}
得到这个错误..我几乎尝试使用所有协议
javax.mail.MessagingException:Connection refused:connect;
嵌套异常是:
java.net.ConnectException:Connection refused:connect
at com.sun.mail.imap.IMAPStore.protocolConnect(IMAPStore.java:571)
at javax.mail.Service.connect(Service.java:288)
在javax.mail.Service.connect(Service.java:169)
在ConnectGmail.main(ConnectGmail.java:26)
任何帮助??
解决方案
您需要启用邮件身份验证才能使用它:
设置属性 mail.smtp.auth
到 true
以进行身份验证。
如果为true,请尝试使用AUTH命令验证用户。默认为false。
@see Package com.sun.mail.smtp的Javadoc
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();
}
}
}
Got this ERROR .. I almost tried with all the 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)
any help ??
解决方案
You need to enable the mail authentification before you can use it:
Set property mail.smtp.auth
to true
to enalbe authentification.
If true, attempt to authenticate the user using the AUTH command. Defaults to false.
@see Javadoc of Package com.sun.mail.smtp
这篇关于无法连接到我的邮件服务器(java)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文