471,893 Members | 2,092 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,893 software developers and data experts.

Help, Please!!! Can't Send Mail with SmtpClient

Hi, my jsp page uses sun.net.smtp.SmtpClient to send email. It worked fine until the hosted location was moved to another server. Now it generates the sun.net.smtp.SmtpProtocolException and the hosting company can't find what's wrong with it so I'm here hoping somebody can help.

The hosting company tried sending email from the server and it was okay and found no restrictions that prevents my page to access the smtp server.

What could cause the SmtpProtocolException? "locahost" was what I used to connect to the smtp server. When it failed, I tried another smtp server like "mail.xxx.com" for another domain and it worked but the problem is that this server can't let me send mail to other domains except its own domain.


The following is the code responsible for the email: (error follows)
Expand|Select|Wrap|Line Numbers
  1. try
  2. {
  3. client = new SmtpClient(localhost);
  4. client.from(EMAIL_FROM);
  5. client.to(strEmail);
  6. PrintStream message = client.startMessage();
  7. message.println("From: " + EMAIL_FROM);
  8. message.println("To: " + strEmail);
  9. message.println("Subject: " + SUBJECT);
  10. message.println();
  11. ...
  12. client.closeServer(); 
  13. catch(IOException e)
  14. {
  15. <div><%=e%></div>
  16. }
Expand|Select|Wrap|Line Numbers
  1. sun.net.smtp.SmtpProtocolException: 
  2. at sun.net.smtp.SmtpClient.issueCommand(SmtpClient.ja va:48) 
  3. at sun.net.smtp.SmtpClient.closeServer(SmtpClient.jav a:38) 
  4. at sun.net.NetworkClient.openServer(NetworkClient.jav a:117) 
  5. at sun.net.smtp.SmtpClient.openServer(SmtpClient.java :111) 
  6. at sun.net.smtp.SmtpClient.(SmtpClient.java:156) 
  7. at org.apache.jsp.dbg.email_005fpass2_jsp._jspService (email_005fpass2_jsp.java:134) 
  8. at org.apache.jasper.runtime.HttpJspBase.service(Http JspBase.java:133) 
  9. at javax.servlet.http.HttpServlet.service(HttpServlet .java:856) 
  10. at org.apache.jasper.servlet.JspServletWrapper.servic e(JspServletWrapper.java:311) 
  11. at org.apache.jasper.servlet.JspServlet.serviceJspFil e(JspServlet.java:301) 
  12. at org.apache.jasper.servlet.JspServlet.service(JspSe rvlet.java:248) 
  13. at javax.servlet.http.HttpServlet.service(HttpServlet .java:856) 
  14. at org.apache.catalina.core.ApplicationFilterChain.in ternalDoFilter(ApplicationFilterChain.java:284) 
  15. at org.apache.catalina.core.ApplicationFilterChain.do Filter(ApplicationFilterChain.java:204) 
  16. at org.apache.catalina.core.StandardWrapperValve.invo ke(StandardWrapperValve.java:256) 
  17. at org.apache.catalina.core.StandardValveContext.invo keNext(StandardValveContext.java:151) 
  18. at org.apache.catalina.core.StandardPipeline.invoke(S tandardPipeline.java:564) 
  19. at org.apache.catalina.core.StandardContextValve.invo keInternal(StandardContextValve.java:245) 
  20. at org.apache.catalina.core.StandardContextValve.invo ke(StandardContextValve.java:199) 
  21. at org.apache.catalina.core.StandardValveContext.invo keNext(StandardValveContext.java:151) 
  22. at org.apache.catalina.authenticator.AuthenticatorBas e.invoke(AuthenticatorBase.java:509) 
  23. at org.apache.catalina.core.StandardValveContext.invo keNext(StandardValveContext.java:149) 
  24. at org.apache.catalina.core.StandardPipeline.invoke(S tandardPipeline.java:564) 
  25. at org.apache.catalina.core.StandardHostValve.invoke( StandardHostValve.java:195) 
  26. at org.apache.catalina.core.StandardValveContext.invo keNext(StandardValveContext.java:151) 
  27. at org.apache.catalina.valves.ErrorReportValve.invoke (ErrorReportValve.java:164) 
  28. at org.apache.catalina.core.StandardValveContext.invo keNext(StandardValveContext.java:149) 
  29. at org.apache.catalina.core.StandardPipeline.invoke(S tandardPipeline.java:564) 
  30. at org.apache.catalina.core.StandardEngineValve.invok e(StandardEngineValve.java:156) 
  31. at org.apache.catalina.core.StandardValveContext.invo keNext(StandardValveContext.java:151) 
  32. at org.apache.catalina.core.StandardPipeline.invoke(S tandardPipeline.java:564) 
  33. at org.apache.catalina.core.ContainerBase.invoke(Cont ainerBase.java:972) 
  34. at org.apache.coyote.tomcat5.CoyoteAdapter.service(Co yoteAdapter.java:211) 
  35. at org.apache.jk.server.JkCoyoteHandler.invoke(JkCoyo teHandler.java:309) 
  36. at org.apache.jk.common.HandlerRequest.invoke(Handler Request.java:387) 
  37. at org.apache.jk.common.ChannelSocket.invoke(ChannelS ocket.java:673) 
  38. at org.apache.jk.common.ChannelSocket.processConnecti on(ChannelSocket.java:615) 
  39. at org.apache.jk.common.SocketConnection.runIt(Channe lSocket.java:786) 
  40. at org.apache.tomcat.util.threads.ThreadPool$ControlR unnable.run(ThreadPool.java:677) 
  41. at java.lang.Thread.run(Thread.java:536)
Oct 22 '08 #1
2 3640
post the whole tomcat log. mainly the line "caused by" for ur exception. most likely u r failing to authenticate or some firewall issues
Oct 22 '08 #2
3,112 Expert 2GB
post the whole tomcat log. mainly the line "caused by" for ur exception.
Please use [CODE] ... [/code] tags when posting it - it's not strictly required when posting a textfile, but it clearly shows, what belongs together. Also, please certainly use them when posting code. We do require it in that case. I've added CODE tags to your post above.

Nepomuk (Moderator)
Oct 22 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

1 post views Thread by chalk | last post: by
6 posts views Thread by erdem kemer | last post: by
4 posts views Thread by herbert | last post: by
4 posts views Thread by | last post: by
reply views Thread by YellowAndGreen | last post: by
reply views Thread by zermasroor | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.