当前位置: 代码迷 >> J2EE >> 用javamail 发邮件 报空指针,该怎么处理
  详细解决方案

用javamail 发邮件 报空指针,该怎么处理

热度:560   发布时间:2016-04-22 01:53:36.0
用javamail 发邮件 报空指针
代码如下
SimpleMailMessage simple=new SimpleMailMessage();
mailSender.setHost("smtp.qq.com");
mailSender.setUsername("544645352@qq.com");
mailSender.setPassword("19890126520zhi");

System.out.println(mailSender.getHost());
System.out.println(mailSender.getUsername());
System.out.println(mailSender.getPassword());
simple.setTo("475376081@qq.com"); //设置收件人
simple.setCc("398974002@qq.com"); //设置抄送
simple.setBcc("373197082@qq.com"); //设置暗送
simple.setFrom("544645352@qq.com"); //设置发件人
simple.setSubject(this.getZhuti());//设置主题
simple.setText(this.getNeirong()); //设置内容
System.out.println(this.getZhuti());
System.out.println(this.getNeirong());
mailSender.send(simple); //使用邮件发送器 发送

 错误如下:
java.lang.NullPointerException
at org.springframework.mail.MailSendException.getMessage(MailSendException.java:111)
at org.apache.struts2.dispatcher.Dispatcher.sendError(Dispatcher.java:770)
at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:505)
at org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77)
at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:91)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:215)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
at cn.com.filter.SetCharacterFilter.doFilter(SetCharacterFilter.java:21)
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:213)
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:174)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:874)
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:689)
at java.lang.Thread.run(Thread.java:595)


求解 谢谢各位

------解决方案--------------------
at org.springframework.mail.MailSendException.getMessage(MailSendException.java:111)
点这个进去看看,
感觉
simple.setSubject(this.getZhuti());//设置主题
simple.setText(this.getNeirong()); //设置内容
可能是这两句中取到的内容为空。