Results 1 to 2 of 2
  1. #1
    jfcup is offline Member
    Join Date
    Oct 2008
    Posts
    2
    Rep Power
    0

    Default 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.

    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)

    ---------------------------------------------------------------------

  2. #2
    Vijay Mishra is offline Member
    Join Date
    Nov 2008
    Posts
    5
    Rep Power
    0

    Default

    Just change the statement.
    Let "To" comes before "From" and check it.I hope so it works
    as SMTP generally works on following command

    HELO (connection establishment)
    MAIL (specifies who's sending mail)
    RCPT (specifies who's getting it)
    DATA (body of message)
    QUIT

    Let me know if you have query

Similar Threads

  1. How to send SMS and E-Mail on Jboss shutdown.
    By thufail@neevtech.com in forum Java Servlet
    Replies: 1
    Last Post: 12-29-2008, 08:51 AM
  2. JSP send mail script not working.
    By profuse in forum Java Applets
    Replies: 1
    Last Post: 05-27-2008, 06:37 AM
  3. Replies: 2
    Last Post: 05-05-2008, 06:01 AM
  4. A Client to Send SMTP Mail
    By Java Tip in forum java.net
    Replies: 0
    Last Post: 04-07-2008, 08:06 PM
  5. Send a pic through mail, in java
    By lenny in forum Advanced Java
    Replies: 1
    Last Post: 07-25-2007, 02:49 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •