急求帮助关于java mail发送邮件javax.mail.MessagingException: [EOF]异常

时间:2022-12-12 18:08:56
DEBUG SMTP: EOF: [EOF]
javax.mail.MessagingException: [EOF]
at com.sun.mail.smtp.SMTPTransport.issueCommand(SMTPTransport.java:1481)
at com.sun.mail.smtp.SMTPTransport.issueSendCommand(SMTPTransport.java:1512)
at com.sun.mail.smtp.SMTPTransport.finishData(SMTPTransport.java:1321)
at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:637)
at com.richmond.util.Mail.sendMail(Mail.java:65)
at com.richmond.acl.web.action.LoginAction.sendMail(LoginAction.java:144)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.apache.struts.actions.DispatchAction.dispatchMethod(DispatchAction.java:270)
at org.apache.struts.actions.DispatchAction.execute(DispatchAction.java:187)
at org.springframework.web.struts.DelegatingActionProxy.execute(DelegatingActionProxy.java:106)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:431)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:236)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:414)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:78)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:77)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:215)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
at org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:174)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:77)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:215)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:210)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:174)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:151)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:870)
at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:685)
at java.lang.Thread.run(Unknown Source)
14:51:30,609  WARN RequestProcessor:528 - Unhandled Exception thrown: class javax.mail.MessagingException
14:51:30,609 ERROR [action]:250 - Servlet.service() for servlet action threw exception
javax.mail.MessagingException: [EOF]
at com.sun.mail.smtp.SMTPTransport.issueCommand(SMTPTransport.java:1481)
at com.sun.mail.smtp.SMTPTransport.issueSendCommand(SMTPTransport.java:1512)
at com.sun.mail.smtp.SMTPTransport.finishData(SMTPTransport.java:1321)
at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:637)
at com.richmond.util.Mail.sendMail(Mail.java:65)
at com.richmond.acl.web.action.LoginAction.sendMail(LoginAction.java:144)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.apache.struts.actions.DispatchAction.dispatchMethod(DispatchAction.java:270)
at org.apache.struts.actions.DispatchAction.execute(DispatchAction.java:187)
at org.springframework.web.struts.DelegatingActionProxy.execute(DelegatingActionProxy.java:106)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:431)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:236)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:414)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:78)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:77)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:215)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
at org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:174)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:77)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:215)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:210)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:174)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:151)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:870)
at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:685)
at java.lang.Thread.run(Unknown Source)

5 个解决方案

#1


以下是原代码:
import java.util.Properties;

import javax.mail.Address;
import javax.mail.Authenticator;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Multipart;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;




public class Mail {

private Session session;

private Properties proper;


private String userName ;

private String password ;

private String smtp ;
private String systemMail;

public Mail(){
smtp = DataTools.getMessageResources("mail.smtp");
proper = new Properties();
proper.setProperty("mail.smtp.host",smtp );
proper.setProperty("mail.smtp.auth","true");//需要验证目前所有的服务都要验证
systemMail = DataTools.getMessageResources("system.email");
password = DataTools.getMessageResources("system.mail.password");
userName = DataTools.getMessageResources("system.mail.userName");
}

/**
 * 发送邮件
 * @param email 收件人的地址
 * @param title 标题
 * @param content 内客
 * @throws MessagingException 
 * @throws AddressException 
 */
public void sendMail(String email,String title,String content) throws AddressException, MessagingException{
session = Session.getDefaultInstance(proper);
session.setDebug(true);
//邮件对象
MimeMessage message = new MimeMessage(session);
message.setSender(new InternetAddress(systemMail));
message.setRecipient(Message.RecipientType.TO, new InternetAddress(email));
message.setSubject(title);
message.setText(content);
message.setSentDate(DataTools.getThisDate());
message.saveChanges();
Transport ts = session.getTransport("smtp");
ts.connect(smtp, userName, password);
ts.sendMessage(message, message.getAllRecipients());
ts.close();
System.out.println("邮件发送成功");


}

}

#2


帮顶
建议楼主先确定邮件服务器是不是可以连上。
排除防火墙等问题。
然后可以看看邮件服务器的日志(用自己公司服务器做测试)

(我以前写过一个现在全忘了,哎)

#3


代码没问题,换一个smtp服务器看看!

#4


DEBUG SMTP: EOF: [EOF] 

感觉是对方服务器主动段开了连接!你这面没有读到应有的回应数据!

#5


我已经解决了,我知道了就是21cn.的垃圾软件的原因,谢谢

#1


以下是原代码:
import java.util.Properties;

import javax.mail.Address;
import javax.mail.Authenticator;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Multipart;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;




public class Mail {

private Session session;

private Properties proper;


private String userName ;

private String password ;

private String smtp ;
private String systemMail;

public Mail(){
smtp = DataTools.getMessageResources("mail.smtp");
proper = new Properties();
proper.setProperty("mail.smtp.host",smtp );
proper.setProperty("mail.smtp.auth","true");//需要验证目前所有的服务都要验证
systemMail = DataTools.getMessageResources("system.email");
password = DataTools.getMessageResources("system.mail.password");
userName = DataTools.getMessageResources("system.mail.userName");
}

/**
 * 发送邮件
 * @param email 收件人的地址
 * @param title 标题
 * @param content 内客
 * @throws MessagingException 
 * @throws AddressException 
 */
public void sendMail(String email,String title,String content) throws AddressException, MessagingException{
session = Session.getDefaultInstance(proper);
session.setDebug(true);
//邮件对象
MimeMessage message = new MimeMessage(session);
message.setSender(new InternetAddress(systemMail));
message.setRecipient(Message.RecipientType.TO, new InternetAddress(email));
message.setSubject(title);
message.setText(content);
message.setSentDate(DataTools.getThisDate());
message.saveChanges();
Transport ts = session.getTransport("smtp");
ts.connect(smtp, userName, password);
ts.sendMessage(message, message.getAllRecipients());
ts.close();
System.out.println("邮件发送成功");


}

}

#2


帮顶
建议楼主先确定邮件服务器是不是可以连上。
排除防火墙等问题。
然后可以看看邮件服务器的日志(用自己公司服务器做测试)

(我以前写过一个现在全忘了,哎)

#3


代码没问题,换一个smtp服务器看看!

#4


DEBUG SMTP: EOF: [EOF] 

感觉是对方服务器主动段开了连接!你这面没有读到应有的回应数据!

#5


我已经解决了,我知道了就是21cn.的垃圾软件的原因,谢谢