我正在使用以下代码从 Java 应用程序发送电子邮件。在我的计算机上它工作正常,在第二台计算机上也可以,但在另一台计算机(在同一网络中)上却不行,尽管我们使用相同的连接设置。
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
它不能在一台计算机上运行的原因可能是什么?