gpt4 book ai didi

java - 通过 jsp (SMTP EXIM) 发送电子邮件时出错

转载 作者:太空宇宙 更新时间:2023-11-03 15:03:51 26 4
gpt4 key购买 nike

Properties props = new Properties();
props.put("mail.smtp.host", "mail.xxx.net");
props.put("mail.smtp.port","25");
props.put("mail.smtp.ssl.enable", "false");
props.put("mail.debug", "true");
props.put("mail.smtp.debug", "true");
props.put ("mail.smtp.starttls.enable", "true");
props.put("mail.transport.protocol", "smtp");
props.put("mail.smtp.socketFactory.port", "587");
props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
props.put("mail.smtp.socketFactory.fallback", "false");
java.security.Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
Authenticator auth = new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication(){
return new PasswordAuthentication("signup@xxx.net", "xxx");
}
};
Session s = Session.getInstance(props,auth);
MimeMessage message = new MimeMessage(s);
InternetAddress from = new InternetAddress("admin@xxx.net");
message.setFrom(from);
InternetAddress to = new InternetAddress("muhammadanish@gmail.com");
message.addRecipient(Message.RecipientType.TO, to);
message.setSubject("Test from JavaMail.");
//message.setText("Hello from JavaMail!");
message.setContent("Hello from JavaMail!", "text/plain");
message.saveChanges();
Transport transport = s.getTransport("smtp");
transport.connect("mail.xxx.net","signup@xxx.net","xxx");
transport.sendMessage(message,message.getAllRecipients());
transport.close();

但是我得到一个错误:

The server encountered an internal error () that prevented it from fulfilling this request.

堆栈跟踪:

org.apache.jasper.JasperException: javax.servlet.ServletException: javax.mail.MessagingException: Could not connect to SMTP host: mail.xxx.net, port: 25;
nested exception is:
javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection?
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:549)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:455)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)

根本原因:

javax.servlet.ServletException: javax.mail.MessagingException: Could not connect to SMTP host: mail.xxx.net, port: 25;
nested exception is:
javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection?
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:911)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:840)
org.apache.jsp.index_jsp._jspService(index_jsp.java:87)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)

当我排除代码 SSL 和 TSL 时

调试结果为

DEBUG: JavaMail version 1.4.5
DEBUG: successfully loaded resource: /META-INF/javamail.default.providers
DEBUG: Tables of loaded providers
DEBUG: Providers Listed By Class Name: {com.sun.mail.smtp.SMTPSSLTransport=javax.mail.Provider[TRANSPORT,smtps,com.sun.mail.smtp.SMTPSSLTransport,Sun Microsystems, Inc], com.sun.mail.smtp.SMTPTransport=javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc], com.sun.mail.imap.IMAPSSLStore=javax.mail.Provider[STORE,imaps,com.sun.mail.imap.IMAPSSLStore,Sun Microsystems, Inc], com.sun.mail.pop3.POP3SSLStore=javax.mail.Provider[STORE,pop3s,com.sun.mail.pop3.POP3SSLStore,Sun Microsystems, Inc], com.sun.mail.imap.IMAPStore=javax.mail.Provider[STORE,imap,com.sun.mail.imap.IMAPStore,Sun Microsystems, Inc], com.sun.mail.pop3.POP3Store=javax.mail.Provider[STORE,pop3,com.sun.mail.pop3.POP3Store,Sun Microsystems, Inc]}
DEBUG: Providers Listed By Protocol: {imaps=javax.mail.Provider[STORE,imaps,com.sun.mail.imap.IMAPSSLStore,Sun Microsystems, Inc], imap=javax.mail.Provider[STORE,imap,com.sun.mail.imap.IMAPStore,Sun Microsystems, Inc], smtps=javax.mail.Provider[TRANSPORT,smtps,com.sun.mail.smtp.SMTPSSLTransport,Sun Microsystems, Inc], pop3=javax.mail.Provider[STORE,pop3,com.sun.mail.pop3.POP3Store,Sun Microsystems, Inc], pop3s=javax.mail.Provider[STORE,pop3s,com.sun.mail.pop3.POP3SSLStore,Sun Microsystems, Inc], smtp=javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc]}
DEBUG: successfully loaded resource: /META-INF/javamail.default.address.map
DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc]
DEBUG SMTP: useEhlo true, useAuth false
DEBUG SMTP: trying to connect to host "mail.xxx.net", port 25, isSSL false


Mar 23, 2013 8:52:13 AM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [jsp] in context with path [/KKS] threw exception [javax.servlet.ServletException: javax.mail.MessagingException: Could not connect to SMTP host: mail.xxx.net, port: 25;
nested exception is:
java.net.ConnectException: Connection timed out: connect] with root cause
java.net.ConnectException: Connection timed out: connect

最佳答案

正如其他人所说,摆脱套接字工厂的东西。

您会在 JavaMail FAQ 中找到许多其他帮助

关于java - 通过 jsp (SMTP EXIM) 发送电子邮件时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15576341/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com