什么阻止了我的 Java 邮件?

What is blocking my Java mail?

我有一个使用 "pure" JSP、Servlet 和 Hibernate 开发的 Web 应用程序。它还与 Java 邮件一起工作。 Java 邮件功能几乎可以在我们在这里测试的每台机器上运行,直到今天。它在部署服务器上不起作用(它实际上是一个 windows 7 PC,我认为它有一个 GUI)。它给了我以下错误

com.sun.mail.util.MailConnectException: Couldn't connect to host, port: mail.xxx.com, 25; timeout -1;
  nested exception is:
        java.net.ConnectException: Connection timed out: connect
        at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:2053)
        at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:69
7)
        at javax.mail.Service.connect(Service.java:386)
        at javax.mail.Service.connect(Service.java:245)
        at javax.mail.Service.connect(Service.java:194)
        at javax.mail.Transport.send0(Transport.java:253)
        at javax.mail.Transport.send(Transport.java:124)
        at RemindeWorker.Listener.MailClient.sendEmail(MailClient.java:65)
        at Filter.AuthenticationFilter_Level1.doFilter(AuthenticationFilter_Leve
l1.java:99)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
icationFilterChain.java:241)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
ilterChain.java:208)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperV
alve.java:220)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextV
alve.java:122)
        at org.apache.catalina.authenticator.AuthenticatorBase.invoke(Authentica
torBase.java:503)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.j
ava:170)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.j
ava:103)
        at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:
950)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineVal
ve.java:116)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.jav
a:421)
        at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp
11Processor.java:1070)
        at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(
AbstractProtocol.java:611)
        at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoin
t.java:316)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.
java:1142)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor
.java:617)
        at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskTh
read.java:61)
        at java.lang.Thread.run(Thread.java:745)
Caused by: java.net.ConnectException: Connection timed out: connect
        at java.net.DualStackPlainSocketImpl.connect0(Native Method)
        at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketI
mpl.java:79)
        at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.ja
va:345)
        at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocket
Impl.java:206)
        at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java
:188)
        at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
        at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
        at java.net.Socket.connect(Socket.java:589)
        at java.net.Socket.connect(Socket.java:538)
        at com.sun.mail.util.SocketFetcher.createSocket(SocketFetcher.java:312)
        at com.sun.mail.util.SocketFetcher.getSocket(SocketFetcher.java:236)
        at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:2019)
        ... 25 more
Level1 executed
NUM is: 1

下面是我的代码。

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package RemindeWorker.Listener;

import java.util.List;
import java.util.Properties;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;

/**
 *
 * @author Yohan
 */
public class MailClient 
{

    public void sendEmail(final String userName, final String password, final String host, final String html, final List<String>emails, String subject) throws MessagingException
    {
        System.out.println("User Name: "+userName);
        System.out.println("Password: "+password);
        System.out.println("Host: "+host);

//          String host="mail.xxx.com";  
//          final String user="abc@xxx.com";//change accordingly  
//          final String password="knight55";//change accordingly  



           //Get the session object  
           Properties props = new Properties();  
           props.put("mail.smtp.host",host);  
           props.put("mail.smtp.auth", "true");  

           Session session = Session.getDefaultInstance(props,  
            new javax.mail.Authenticator() {  
              protected PasswordAuthentication getPasswordAuthentication() {  
            return new PasswordAuthentication(userName,password);  
              }  
            });  

           if(!emails.isEmpty())
           {
                   //Compose the message  
                    InternetAddress[] address = new InternetAddress[emails.size()];
                    for (int i = 0; i < emails.size(); i++) {
                        address[i] = new InternetAddress(emails.get(i));
                    }

                     MimeMessage message = new MimeMessage(session);  
                     message.setFrom(new InternetAddress(userName));  
                      message.setRecipients(Message.RecipientType.TO, address);
                     message.setSubject(subject);  

                     message.setContent(html,"text/html");

                    //send the message  
                     Transport.send(message);  

                     System.out.println("message sent successfully...");  
           }
           else
           {
               System.out.println("No Recieptions");
           }


    }
}

什么样的事情会阻止我的应用程序发送电子邮件?服务器有 JRE 8 和 XAMPP。服务器管理员说防火墙已关闭!

问题是服务器的 25 端口被不知何故封锁了。 SMTP 的默认端口是端口 25。我使用 Properties 更改了 Java 邮件的端口并且成功了。