title: JavaMail javax.mail.AuthenticationFailedException
body: <p>I'm not familiar with this function to send mail in java.I'm getting an error while sending email to confirm a user after registered.</p>
  
  <p>Below is code in <strong>TextMail :</strong> </p>
  
  <pre><code>public class TextMail extends HttpServlet {
  
  static String sender_email = "abc@gmail.com";
  static String password = "aaaa1111";
  static String host = "smtp.gmail.com";
  static String port = "465";
  
  private static class MailAuthenticator extends javax.mail.Authenticator {
  
      @Override
      public PasswordAuthentication getPasswordAuthentication() {
          return new PasswordAuthentication(sender_email, password);
      }
  }
  
  protected void processRequest(HttpServletRequest request, HttpServletResponse response)
          throws ServletException, IOException {
      response.setContentType("text/html;charset=UTF-8");
  
      try {
          System.out.println("inside textmail");
  
          System.out.println(request.getParameter("to"));
          System.out.println(request.getParameter("text"));
          System.out.println(request.getParameter("subject"));
  
          String to = request.getParameter("to");
          String text = request.getParameter("text");
          String subject = request.getParameter("subject");
  
          Properties props = new Properties();
          props.put("mail.smtp.user", sender_email);
          props.put("mail.smtp.host", host);
          props.put("mail.smtp.port", port);
          props.put("mail.smtp.starttls.enable", "true");
          props.put("mail.smtp.auth", "true");
          props.put("mail.smtp.socketFactory.port", port);
          props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
          props.put("mail.smtp.socketFactory.fallback", "false");
  
          Authenticator auth = new MailAuthenticator();
          Session session = Session.getInstance(props, auth);
  
          Message message = new MimeMessage(session);
          message.setFrom(new InternetAddress(sender_email));
          message.setSubject(subject);
          message.setText(text);
  
          message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
  
          Transport.send(message);
          System.out.println("execute textmail");
      } catch (Exception mex) {
          throw new ServletException(mex);
      }
  }
  </code></pre>
  
  <p>the parameters for the above code is sent from another <strong>servelet :</strong></p>
  
  <pre><code>response.sendRedirect("TextMail?to="+ul.getEmail()+"&amp;text=path?UID="+u.getIduser()+"&amp;subject=Comfirmation");
  </code></pre>
  
  <p>and these parameters passing successfully to the TextMail </p>