JavaMail:如何解决SocketException? [英] JavaMail: How to solve SocketException?

查看:253
本文介绍了JavaMail:如何解决SocketException?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用以下代码从Java应用程序发送电子邮件.在我的计算机上,它也可以正常工作,在第二台计算机上也可以,但是在另一台计算机(在同一网络中)却不能,尽管我们使用的是相同的连接设置.

I am using the following code to send emails from a Java application. On my computer it works fine, on second computer too, but on another computer (in the same network) it doesn't, although we're using the same connection settings.

public void connect() throws MessagingException
{
    Authenticator auth = new Authenticator(){ 
        @Override
        protected PasswordAuthentication getPasswordAuthentication()
        {
            return new PasswordAuthentication(smtpUser, smtpPassword);
        }
    };
    Properties props = new Properties();
    props.put("mail.smtp.host", this.smtpServer);
    props.put("mail.smtp.auth", true); 

    session = Session.getDefaultInstance(props, auth);

    store = session.getStore(this.protocol);
    store.connect(this.mailboxServer, this.user, this.password);  //<-- exception is thrown here

}

这是我得到的例外:

javax.mail.MessagingException: connect failed; 
nested exception is: 
    java.net.SocketException: Permission denied: connect
    at com.sun.mail.pop3.POP3Store.protocolConnect(POP3Store.java:161)
    at javax.mail.Service.connect(Service.java:288)
    at javax.mail.Service.connect(Service.java:169)
    at com.myapp.MailboxConnection.connect(MailboxConnection.java:66)
caused by: java.net.SocketException: Permission denied: connect

它不能在一台计算机上运行的原因是什么?

What could be the reason that it doesn't work on one computer?

推荐答案

通过卸载Norton AntiVirus解决的问题

problem solved by uninstalling Norton AntiVirus

这篇关于JavaMail:如何解决SocketException?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆