title: Authentication Failed exception - In the middle of bulk mail sending code
body: <p>We have a thread program that sends bulk mail.
  The information like </p>
  
  <pre><code>1. To
  2. Subject
  Etc.
  </code></pre>
  
  <p>are fetched from database, mail is composed and pushed to SMTP server.
  One of our customer sent a bulk mail with 2390 email.
  After sending 40 emails, suddenly the following exception occurred</p>
  
  <pre><code>EXCEPTION
  javax.mail.AuthenticationFailedException
  
  STACKTRACE
  javax.mail.Service.connect(Service.java:306)
  javax.mail.Service.connect(Service.java:156)
  javax.mail.Service.connect(Service.java:105)
  ...............
  java.lang.Thread.run(Thread.java:619)
  </code></pre>
  
  <p>and the rest 2350 emails failed.</p>
  
  <p>Why does this occur?</p>
  
  <p>Thanks for the Suggestions and Help</p>
  
  <p>Ezhil</p>
  
  <p>==============================================</p>
  
  <p>My Code:</p>
  
  <pre><code>Session session = Session.getInstance(properties, new SMTPAuthenticator(smtpAuthenticationBean.getUserName(), smtpAuthenticationBean.getPassword()))) : (Session.getInstance(properties, null))
  for each email id
  {
  
      InternetAddress iAddress    = new InternetAddress(getFromHeader(jobListBean.getFromDisplayName(), jobListBean.getFromEmail()));
      Multipart multipart         = new MimeMultipart(); // By default, Content Type is "mixed"
  
  
      msg.setSubject(jobListBean.getSubject());
      msg.setSentDate(new Date());
  
      // Set Internet Headers
      msg.setHeader("Importance", priorityType);
  
      msg.setHeader("Disposition-Notification-To", jobListBean.getFromEmail());
  
      FileDataSource fds = new FileDataSource(tempAbsoluteFileName);
      MimeBodyPart htmlBodyPart = new MimeBodyPart();
  
      String fileContent = org.objectstyle.woproject.util.FileStringScanner.stringFromFile(new File(tempAbsoluteFileName));
      htmlBodyPart.setText(fileContent);
      multipart.addBodyPart(htmlBodyPart);
  
      msg.setContent(multipart);
  
      InternetAddress address[] = InternetAddress.parse(emailList.toString(), true);
  
      Transport smtpTransport = session.getTransport();
      smtpTransport.addTransportListener(this);
  
      smtpTransport.connect();
  
      smtpTransport.sendMessage(msg, address);
  
      smtpTransport.close();
  
      File file = new File(tempAbsoluteFileName);
      file.delete();
  }
  </code></pre>
  
  <p>====================================</p>
  
  <p>Yes there is a chance for smtp server to get disconnected or not respond
  since its  thread program, i can say at max case more than 1000 mails 
  can get pushed in to smtp server at same time.</p>
  
  <p>At any cast, will smtp server throw </p>
  
  <pre><code>EXCEPTION
  javax.mail.AuthenticationFailedException
  
  STACKTRACE
  javax.mail.Service.connect(Service.java:306)
  javax.mail.Service.connect(Service.java:156)
  javax.mail.Service.connect(Service.java:105)
  ...............
  java.lang.Thread.run(Thread.java:619)
  </code></pre>
  
  <p>if it is not able to serve our request</p>
  
  <p>=============</p>
  
  <p>Still i need to look in to SMTP server log.</p>
  
  <p>Ezhil</p>