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.

Thanks

The following is the code responsible for the email: (error follows)
-------------------------------------------------------------

try
{
client = new SmtpClient(localhost);
client.from(EMAIL_FROM);
client.to(strEmail);
PrintStream message = client.startMessage();
message.println("From: " + EMAIL_FROM);
message.println("To: " + strEmail);
message.println("Subject: " + SUBJECT);
message.println();
...
client.closeServer(); 
} 
catch(IOException e)
{
<div><%=e%></div>
}

Exceptions
-----------------------------------------------------------

sun.net.smtp.SmtpProtocolException:
at sun.net.smtp.SmtpClient.issueCommand(SmtpClient.ja va:48)
at sun.net.smtp.SmtpClient.closeServer(SmtpClient.jav a:38)
at sun.net.NetworkClient.openServer(NetworkClient.jav a:117)
at sun.net.smtp.SmtpClient.openServer(SmtpClient.java :111)
at sun.net.smtp.SmtpClient.(SmtpClient.java:156)
at org.apache.jsp.dbg.email_005fpass2_jsp._jspService (email_005fpass2_jsp.java:134)
at org.apache.jasper.runtime.HttpJspBase.service(Http JspBase.java:133)
at javax.servlet.http.HttpServlet.service(HttpServlet .java:856)
at org.apache.jasper.servlet.JspServletWrapper.servic e(JspServletWrapper.java:311)
at org.apache.jasper.servlet.JspServlet.serviceJspFil e(JspServlet.java:301)
at org.apache.jasper.servlet.JspServlet.service(JspSe rvlet.java:248)
at javax.servlet.http.HttpServlet.service(HttpServlet .java:856)
at org.apache.catalina.core.ApplicationFilterChain.in ternalDoFilter(ApplicationFilterChain.java:284)
at org.apache.catalina.core.ApplicationFilterChain.do Filter(ApplicationFilterChain.java:204)
at org.apache.catalina.core.StandardWrapperValve.invo ke(StandardWrapperValve.java:256)
at org.apache.catalina.core.StandardValveContext.invo keNext(StandardValveContext.java:151)
at org.apache.catalina.core.StandardPipeline.invoke(S tandardPipeline.java:564)
at org.apache.catalina.core.StandardContextValve.invo keInternal(StandardContextValve.java:245)
at org.apache.catalina.core.StandardContextValve.invo ke(StandardContextValve.java:199)
at org.apache.catalina.core.StandardValveContext.invo keNext(StandardValveContext.java:151)
at org.apache.catalina.authenticator.AuthenticatorBas e.invoke(AuthenticatorBase.java:509)
at org.apache.catalina.core.StandardValveContext.invo keNext(StandardValveContext.java:149)
at org.apache.catalina.core.StandardPipeline.invoke(S tandardPipeline.java:564)
at org.apache.catalina.core.StandardHostValve.invoke( StandardHostValve.java:195)
at org.apache.catalina.core.StandardValveContext.invo keNext(StandardValveContext.java:151)
at org.apache.catalina.valves.ErrorReportValve.invoke (ErrorReportValve.java:164)
at org.apache.catalina.core.StandardValveContext.invo keNext(StandardValveContext.java:149)
at org.apache.catalina.core.StandardPipeline.invoke(S tandardPipeline.java:564)
at org.apache.catalina.core.StandardEngineValve.invok e(StandardEngineValve.java:156)
at org.apache.catalina.core.StandardValveContext.invo keNext(StandardValveContext.java:151)
at org.apache.catalina.core.StandardPipeline.invoke(S tandardPipeline.java:564)
at org.apache.catalina.core.ContainerBase.invoke(Cont ainerBase.java:972)
at org.apache.coyote.tomcat5.CoyoteAdapter.service(Co yoteAdapter.java:211)
at org.apache.jk.server.JkCoyoteHandler.invoke(JkCoyo teHandler.java:309)
at org.apache.jk.common.HandlerRequest.invoke(Handler Request.java:387)
at org.apache.jk.common.ChannelSocket.invoke(ChannelS ocket.java:673)
at org.apache.jk.common.ChannelSocket.processConnecti on(ChannelSocket.java:615)
at org.apache.jk.common.SocketConnection.runIt(Channe lSocket.java:786)
at org.apache.tomcat.util.threads.ThreadPool$ControlR unnable.run(ThreadPool.java:677)
at java.lang.Thread.run(Thread.java:536)

most likely, this is a security issue then, and you will need to authenticate with the server to be able to send mail to other domains

And also, since it is on another server, make sure to use its mail.xxx.xxx address. Normally mail servers, will require you to authenticate to send mail from a machine other than itself.

Thanks, since the issue is not solved I turned to re-write the code in JavaMail. I found the following lines on web and it works. The only problem is that it can't send in non-ascii characters like Chinese. For detail, please read my latest message. Thank you very much.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.