2016-07-12 16 views
-2

bereitgestellt abgelehnt Ich habe ein seltsames Problem. Mein SMTP-Server wird auf dem Linux-Host (Postfix/Dovecot) bereitgestellt. Ich habe eine Spring MVC + Tomcat basierte Webanwendung. Wenn ich eine Verbindung zum SMTP-Server auf dem Lunix-Server (Centos) über mein lokales Macbook herstelle, werden die Nachrichten gesendet. Als ich jedoch die Web-App auf Tomcat 7 (mit SSL-Zertifikat von vertrauenswürdigem CA-Zertifikat) auf dem Linux-System bereitgestellt habe, gibt es eine Ausnahme für Verbindung verweigert, nachdem 354 vom Server empfangen wurde. Ich habe auch das offene ssl-Zertifikat für den SMTP-Server generiert und dem vertrauenswürdigen Zertifikat im jdk/jre/lib/security/cacert hinzugefügt. Ich habe sowohl smtp und smtps auf Macbook und Linux-Servern versucht. Auf Dev arbeiten beide. Unter linux (prod) schlägt beides fehl. Bitte beachten Sie, dass es sich sowohl in dev als auch in prod authentifizieren und anmelden kann. Es ist erst nach '354 Daten beenden mit.' Antwort von SMTP, das Verhalten von Dev und Prod unterscheiden sich.SMTP-Verbindung nach 354 nur vom Webserver auf der gleichen Maschine als SMTP-Postfix

Aus meiner Feder appServerContext.xml: -

  <property name="host" value="${linux.host}" /> 
      <property name="port" value="${linux_ssl.port}" /> 
      <property name="username" value="${username}" /> 
      <property name="password" value="${password}" /> 
      <property name="protocol" value="smtps" /> 

    <property name="javaMailProperties"> 
     <props> 
      <prop key="mail.smtps.auth">true</prop> 
      <prop key="mail.smtps.connectiontimeout">5000</prop> 
      <prop key="mail.smtps.sendpartial">true</prop> 
      <prop key="mail.smtps.userset">true</prop> 
      <prop key="mail.mime.charset">UTF-8</prop> 
      <prop key="mail.smtps.isSecure">true</prop> 
      <prop key="mail.smtps.requiresAuthentication">true</prop> 
      <prop key="mail.smtps.port">465</prop> 
      <prop key="mail.smtps.socketFactory.class">javax.net.ssl.SSLSocketFactory</prop> 
      <prop key="mail.smtps.socketFactory.fallback">true</prop> 
      <prop key="mail.smtps.starttls.enable">true</prop> 
      <prop key="mail.debug">true</prop> 
      <!-- <prop key="mail.smtps.ssl.checkserveridentity">true</prop> 
      <prop key="mail.smtps.ssl.trust">*</prop> --> 
     </props> 
    </property> 
</bean> 

SMTP Debuggen von dev log:

354 End data with <CR><LF>.<CR><LF> 
.. 
From: Test User <[email protected]> 
To: [email protected] 
Message-ID: <[email protected] Pro.local> 
Subject: Acknowledgement 
MIME-Version: 1.0 

Von prod (beide SMTP- und smtps nicht an der gleichen Stelle mit der gleicher Fehler)

DATA 
354 End data with <CR><LF>.<CR><LF> 
DEBUG SMTP: IOException while sending, closing, THROW: 
java.net.ConnectException: Connection refused at  java.net.PlainSocketImpl.socketConnect(Native Method) at  
java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339)at  java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200) at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182) at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392) at java.net.Socket.connect(Socket.java:579) sun.security.ssl.SSLSocketImpl.connect(SSLSocketImpl.java:625) at sun.security.ssl.BaseSSLSocketImpl.connect(BaseSSLSocketImpl.java:160) at sun.net.NetworkClient.doConnect(NetworkClient.java:180) at sun.net.www.http.HttpClient.openServer(HttpClient.java:432) at sun.net.www.http.HttpClient.openServer(HttpClient.java:527) at sun.net.www.protocol.https.HttpsClient.<init>(HttpsClient.java:275) at sun.net.www.protocol.https.HttpsClient.New(HttpsClient.java:371) at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.getNewHttpClient(AbstractDelegateHttpsURLConnection.java:191) at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:933) at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:177) at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1301) at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:254) at org.springframework.core.io.UrlResource.getInputStream(UrlResource.java:168) at org.springframework.mail.javamail.MimeMessageHelper$1.getInputStream(MimeMessageHelper.java:1093) at javax.activation.DataHandler.writeTo(DataHandler.java:305) at javax.mail.internet.MimeBodyPart.writeTo(MimeBodyPart.java:1485) at javax.mail.internet.MimeBodyPart.writeTo(MimeBodyPart.java:865) at javax.mail.internet.MimeMultipart.writeTo(MimeMultipart.java:462) at com.sun.mail.handlers.multipart_mixed.writeTo(multipart_mixed.java:103) at javax.activation.ObjectDataContentHandler.writeTo(DataHandler.java:889) at javax.activation.DataHandler.writeTo(DataHandler.java:317) at javax.mail.internet.MimeBodyPart.writeTo(MimeBodyPart.java:1485) at javax.mail.internet.MimeBodyPart.writeTo(MimeBodyPart.java:865) at javax.mail.internet.MimeMultipart.writeTo(MimeMultipart.java:462) at com.sun.mail.handlers.multipart_mixed.writeTo(multipart_mixed.java:103) at javax.activation.ObjectDataContentHandler.writeTo(DataHandler.java:889) at javax.activation.DataHandler.writeTo(DataHandler.java:317) at javax.mail.internet.MimeBodyPart.writeTo(MimeBodyPart.java:1485) at javax.mail.internet.MimeMessage.writeTo(MimeMessage.java:1773) at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:1119) at org.springframework.mail.javamail.JavaMailSenderImpl.doSend(JavaMailSenderImpl.java:433) at org.springframework.mail.javamail.JavaMailSenderImpl.send(JavaMailSenderImpl.java:345) at org.springframework.mail.javamail.JavaMailSenderImpl.send(JavaMailSenderImpl.java:340) 

Ich habe erschöpfend nach dem genauen Problem gesucht. Es gibt zwar ein Beispiel für ConnectionRefused, aber keiner, der direkt nach 354 kam, als ich mich in derselben Box wie der SMTP-Server befand, kam mir zur Kenntnis.

Vielen Dank für Ihre Hilfe, im Voraus!

Antwort

0

Befreien Sie sich von socket factory stuff, you don't need it.

Verwenden Sie eine URLDataSource für einen Teil des Inhalts der Nachricht, die Sie senden? Die Verbindung wird gelöscht, wenn JavaMail versucht, auf einen Teil des Inhalts Ihrer Nachricht zuzugreifen, was eine HTTPS-Verbindung zu einem Server erfordert. Es ist die https-Verbindung, die gelöscht wird, wodurch die SMTP-Verbindung gelöscht wird.

+0

Sie sind tatsächlich richtig @ Bill Shannon, ein 100% korrekt. Ich habe diese URLResource in ServletContextResource geändert und sie hat angefangen zu arbeiten. Du hast meine Woche gerettet und meinen Tag gemacht. Ich danke dir sehr. Gott segne!!! – Yvonne

0

Das Thema wurde zu Recht von @ Bill-Shannon hingewiesen. Es war in der Tat eine URLResource eines PNG-Bildes, die das Problem war. Ich habe es zu einer ServletContextResource geändert und es funktioniert. Hoffentlich findet jemand das nützlich und spart Frustration und Zeit. Besonderer Dank an Bill Shannon für das richtige Nageln !!!