Hi,

> -----Original Message-----
> From: Noel J. Bergman [mailto:[EMAIL PROTECTED]
> Sent: Wednesday, July 23, 2003 1:02 PM
> To: James Users List
> 
> 
> > I am trying to send an email from a servlet with javamail (on a dev
> > machine not the james machine). I have SMTP AUTH on. I create the
> > PasswordAuthentication with a plaintext username and password.
> 
> > javax.mail.AuthenticationFailedException
> 
> This means that the SMTP transport couldn't connect.  Did you add the
> mail.smtp.auth property to the property set?  See the JavaMail package for
> examples.


Yes. Here is the servlet's service method:


public void service(HttpServletRequest req, HttpServletResponse res) throws
ServletException, IOException 
  {      

    Properties props = new Properties();
    props.put("mail.smtp.host", host);
    props.put("mail.smtp.auth", "true");
    
    Authenticator auth = new LsbSmtpAuthenticator();
    Session session = Session.getDefaultInstance(props, auth);
    session.setDebugOut(null);
    
    try {
    
      MimeMessage message = new MimeMessage(session);
      message.setFrom(new InternetAddress(from));
      
      message.addRecipient(Message.RecipientType.TO, new
InternetAddress(to));
      if (null!=cc) message.addRecipient(Message.RecipientType.CC, new
InternetAddress(cc));
      
      message.setSubject(subject);
      
      StringBuffer msg = new StringBuffer("        Submitted Information");
      msg.append("--------------------------------------------");
      msg.append("\n");
      
      Enumeration param_names = req.getParameterNames();
      
      while (param_names.hasMoreElements()) {
        String name = (String)param_names.nextElement();
        msg.append(name); 
        msg.append(":"); 
        msg.append(req.getParameter(name)); 
        msg.append("\n");
        msg.append("   ------------");  
        msg.append("\n");
      }
  
      message.setText(msg.toString());
  
      Transport.send(message); 
    
    } catch (AddressException ae) {
    
      System.out.println("EmailForm AddressException: " + ae);
      res.sendRedirect("/SiteError.jsp");
    
    } catch (MessagingException me) {
    
      System.out.println("EmailForm MessagingException: " + me);
      res.sendRedirect("/SiteError.jsp");
    
    } finally {
    
      res.sendRedirect("/" + thanks_page);   
    
    }
    
  }


> 
>       --- Noel
> 



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to