问题描述
这个测试程序,能发送成功publicclassJavaMail{publicstaticvoidmain(Stringargs[]){Map<String,String>infoMap=newHashMap<String,String>();infoMap.put("hostName","smtp.163.com");infoMap.put("userName","rencheng850908");//用户名infoMap.put("password","aa123456");//密码infoMap.put("mailFrom","rencheng850908@163.com");HtmlMailSendersender=HtmlMailSender.getInstance(infoMap);try{Stringcontent="java测试程序";sender.sendEmail("517018071@qq.com,rencheng850908@163.com","太好了",content,"gbk");System.out.println("Sendemailsuccessfully.");}catch(Exceptione){//TODOAuto-generatedcatchblocke.printStackTrace();}}}而这测试程序,就连不上服务器publicclassJavaMain{publicstaticvoidmain(Stringargs[]){SenderServiceser=newSenderService();Sendersender=ser.getBySender(4);StringserverAdd=sender.getsServerAdd().trim();StringuserName=sender.getsUserName().trim();Stringpassword=sender.getsPassWord().trim();Stringaddress=sender.getsAddress().trim();Map<String,String>infoMap=newHashMap<String,String>();infoMap.put("hostName",serverAdd);infoMap.put("userName",userName);//用户名infoMap.put("password",password);//密码infoMap.put("mailFrom",address);//测试System.out.println(sender.getsAddress());System.out.println(serverAdd);System.out.println(sender.getsPort());System.out.println(sender.getsServerAdd());System.out.println(sender.getsUserName());System.out.println(sender.getsPassWord());HtmlMailSenders=HtmlMailSender.getInstance(infoMap);try{Stringcontent="java测试程序";s.sendEmail("517018071@qq.com,rencheng850908@163.com","收到请回复",content,"gbk");System.out.println("Sendemailsuccessfully.");}catch(Exceptione){//TODOAuto-generatedcatchblocke.printStackTrace();}}}异常信息ConnectionID:1rencheng850908@sohu.comsmtp.sohu.com25smtp.sohu.comrencheng850908aa123456javax.mail.MessagingException:CouldnotconnecttoSMTPhost:localhost,port:25;nestedexceptionis:java.net.ConnectException:Connectionrefused:connectatcom.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1545)atcom.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:453)atjavax.mail.Service.connect(Service.java:313)atjavax.mail.Service.connect(Service.java:172)atjavax.mail.Service.connect(Service.java:121)atjavax.mail.Transport.send0(Transport.java:190)atjavax.mail.Transport.send(Transport.java:120)atcom.mail.method.HtmlMailSender.sendEmail(HtmlMailSender.java:98)atcom.mail.main.JavaMain.main(JavaMain.java:48)Causedby:java.net.ConnectException:Connectionrefused:connectatjava.net.PlainSocketImpl.socketConnect(NativeMethod)atjava.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)atjava.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)atjava.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)atjava.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)atjava.net.Socket.connect(Socket.java:519)atjava.net.Socket.connect(Socket.java:469)atcom.sun.mail.util.SocketFetcher.createSocket(SocketFetcher.java:267)atcom.sun.mail.util.SocketFetcher.getSocket(SocketFetcher.java:227)atcom.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1511)...8morejava.lang.Exceptionatcom.mail.method.HtmlMailSender.sendEmail(HtmlMailSender.java:105)atcom.mail.main.JavaMain.main(JavaMain.java:48)
解决方案
解决方案二:
debug调试
解决方案三:
是不是正常填写和从数据库中读取有什么不同啊?