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

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值