4 Replies Latest reply on Aug 9, 2006 6:26 AM by sunspider

    JavaMail in servlet can't find smtp host.

    sunspider

      Following is the code, the error message is "can't find smtp host", but I can receive Mail with my code, who can tell me why?
      Thanks.
      +++++++++++++++++++++++++++++++++++++++++++++
      public class Servlet1
      extends HttpServlet {
      static class BasicAuthenticator extends Authenticator {
      protected PasswordAuthentication getPasswordAuthentication( ) {

      return new PasswordAuthentication("myname", "mypw");
      }
      }

      private static final String CONTENT_TYPE = "text/html; charset=GBK";
      InitialContext cxt;
      Session sess,sess1;

      public void init() throws ServletException {
      try{
      Properties p = System.getProperties();
      p.put("mail.smtp.host", "smtp.126.com");
      cxt=new InitialContext();
      sess1=(Session)cxt.lookup("java:comp/env/mail/DefaultMail");
      sess= sess1.getInstance(p,new BasicAuthenticator());

      Message msg = new MimeMessage(sess);