java - send mail using localhost instead of gmail -
so, i'm trying send e-mail via javamail , glassfish: here code(i find here http://www.javasrilankansupport.com/2012/05/send-email-in-java-mail-api-using-gmail.html)
private session m_session; private message m_simplemessage; private internetaddress m_fromaddress; private internetaddress m_toaddress; private properties m_properties; @override public void sendmail(string mail) throws exception { seek { m_properties = new properties(); m_properties.put("mail.smtp.host", "smtp.gmail.com"); m_properties.put("mail.smtp.socketfactory.port", "465"); m_properties.put("mail.smtp.socketfactory.class","javax.net.ssl.sslsocketfactory"); m_properties.put("mail.smtp.auth", "true"); m_properties.put("mail.smtp.port", "465"); m_properties.put("mail.debug", "false"); m_properties.put("mail.smtp.ssl.enable", "true"); m_session = session.getdefaultinstance(m_properties,new authenticator() { protected passwordauthentication getpasswordauthentication() { homecoming new passwordauthentication("user@gmail.com","password"); // username , password } }); m_simplemessage = new mimemessage(m_session); m_fromaddress = new internetaddress("user@gmail.com"); m_toaddress = new internetaddress(mail); m_simplemessage.setfrom(m_fromaddress); m_simplemessage.setrecipient(recipienttype.to, m_toaddress); m_simplemessage.setsubject("test letter"); m_simplemessage.setcontent("hi, test letter.","text/plain"); transport.send(m_simplemessage); } grab (messagingexception ex) { ex.printstacktrace(); } }
but after using function on server grab thos exceptions:
javax.mail.messagingexception: not connect smtp host: localhost, port: 25; nested exception is: java.net.connectexception: connection refused: connect @ com.sun.mail.smtp.smtptransport.openserver(smtptransport.java:1934) @ com.sun.mail.smtp.smtptransport.protocolconnect(smtptransport.java:638) @ javax.mail.service.connect(service.java:295) @ javax.mail.service.connect(service.java:176) @ javax.mail.service.connect(service.java:125) @ javax.mail.transport.send0(transport.java:194) @ javax.mail.transport.send(transport.java:124) @ com.kma.summer2012.facade.passwordrecoveryfacadeimpl.sendmail(passwordrecoveryfacadeimpl.java:49) @ com.kma.summer2012.server.crumbsuserserviceimpl.sendmailrecovery(crumbsuserserviceimpl.java:83) @ sun.reflect.nativemethodaccessorimpl.invoke0(native method) @ sun.reflect.nativemethodaccessorimpl.invoke(nativemethodaccessorimpl.java:57) @ sun.reflect.delegatingmethodaccessorimpl.invoke(delegatingmethodaccessorimpl.java:43) @ java.lang.reflect.method.invoke(method.java:601) @ com.google.gwt.user.server.rpc.rpc.invokeandencoderesponse(rpc.java:561) @ com.google.gwt.user.server.rpc.remoteserviceservlet.processcall(remoteserviceservlet.java:208) @ com.google.gwt.user.server.rpc.remoteserviceservlet.processpost(remoteserviceservlet.java:248) @ com.google.gwt.user.server.rpc.abstractremoteserviceservlet.dopost(abstractremoteserviceservlet.java:62) @ javax.servlet.http.httpservlet.service(httpservlet.java:688) @ javax.servlet.http.httpservlet.service(httpservlet.java:770) @ org.apache.catalina.core.standardwrapper.service(standardwrapper.java:1550) @ org.apache.catalina.core.standardwrappervalve.invoke(standardwrappervalve.java:281) @ org.apache.catalina.core.standardcontextvalve.invoke(standardcontextvalve.java:175) @ org.apache.catalina.core.standardpipeline.doinvoke(standardpipeline.java:655) @ org.apache.catalina.core.standardpipeline.invoke(standardpipeline.java:595) @ org.apache.catalina.core.standardhostvalve.invoke(standardhostvalve.java:161) @ org.apache.catalina.connector.coyoteadapter.doservice(coyoteadapter.java:331) @ org.apache.catalina.connector.coyoteadapter.service(coyoteadapter.java:231) @ com.sun.enterprise.v3.services.impl.containermapper$adaptercallable.call(containermapper.java:317) @ com.sun.enterprise.v3.services.impl.containermapper.service(containermapper.java:195) @ com.sun.grizzly.http.processortask.invokeadapter(processortask.java:860) @ com.sun.grizzly.http.processortask.doprocess(processortask.java:757) @ com.sun.grizzly.http.processortask.process(processortask.java:1056) @ com.sun.grizzly.http.defaultprotocolfilter.execute(defaultprotocolfilter.java:229) @ com.sun.grizzly.defaultprotocolchain.executeprotocolfilter(defaultprotocolchain.java:137) @ com.sun.grizzly.defaultprotocolchain.execute(defaultprotocolchain.java:104) @ com.sun.grizzly.defaultprotocolchain.execute(defaultprotocolchain.java:90) @ com.sun.grizzly.http.httpprotocolchain.execute(httpprotocolchain.java:79) @ com.sun.grizzly.protocolchaincontexttask.docall(protocolchaincontexttask.java:54) @ com.sun.grizzly.selectionkeycontexttask.call(selectionkeycontexttask.java:59) @ com.sun.grizzly.contexttask.run(contexttask.java:71) @ com.sun.grizzly.util.abstractthreadpool$worker.dowork(abstractthreadpool.java:532) @ com.sun.grizzly.util.abstractthreadpool$worker.run(abstractthreadpool.java:513) @ java.lang.thread.run(thread.java:722) caused by: java.net.connectexception: connection refused: connect @ java.net.dualstackplainsocketimpl.connect0(native method) @ java.net.dualstackplainsocketimpl.socketconnect(dualstackplainsocketimpl.java:69) @ java.net.abstractplainsocketimpl.doconnect(abstractplainsocketimpl.java:339) @ java.net.abstractplainsocketimpl.connecttoaddress(abstractplainsocketimpl.java:200) @ java.net.abstractplainsocketimpl.connect(abstractplainsocketimpl.java:182) @ java.net.plainsocketimpl.connect(plainsocketimpl.java:157) @ java.net.sockssocketimpl.connect(sockssocketimpl.java:391) @ java.net.socket.connect(socket.java:579) @ java.net.socket.connect(socket.java:528) @ com.sun.mail.util.socketfetcher.createsocket(socketfetcher.java:288) @ com.sun.mail.util.socketfetcher.getsocket(socketfetcher.java:231) @ com.sun.mail.smtp.smtptransport.openserver(smtptransport.java:1900) ... 42 more
as understand, main problem function want utilize localhost , 25 port instead of gmail, , can't figure why. note telnet smtp.gmail.com 25, telnet smtp.gmail.com 465 work well. suggestions cause of this?
try fixing of these common javamail mistakes. see how connect gmail using javamail.
java smtp gmail javamail glassfish-3
No comments:
Post a Comment