title: I need to send mail for multiple recipients
body: <p>In my application, i need to send mail for multiple recipients but i can able to send only one recipient. I try using semi colon that also wont work. I tried but i didnt get any solution, if anyone know about this please make me to know about that.Hope someone will help me to find.</p>
  
  <p>Thanks in advance.</p>
  
  <pre><code>import java.io.File;
  
  import java.io.FileOutputStream;
  import java.io.IOException;
  import java.io.InputStream;
  import java.util.ArrayList;
  import java.util.Collection;
  import java.util.List;
  
  import javax.servlet.ServletContext;
  import javax.servlet.ServletException;
  import javax.servlet.annotation.MultipartConfig;
  import javax.servlet.annotation.WebServlet;
  import javax.servlet.http.HttpServlet;
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpServletResponse;
  import javax.servlet.http.Part;
  
  @WebServlet("/SendMailAttachServlet")
  @MultipartConfig(fileSizeThreshold = 1024 * 1024 * 2,   // 2MB
                  maxFileSize = 1024 * 1024 * 10,         // 10MB
                  maxRequestSize = 1024 * 1024 * 50)      // 50MB
  public class SendMailAttachServlet extends HttpServlet {
      private String host;
      private String port;
  
      public void init() {
          // reads SMTP server setting from web.xml file
          ServletContext context = getServletContext();
         // host = context.getInitParameter("host");
          port = context.getInitParameter("port");
      }
  
      /**
       * handles form submission
       */
      protected void doPost(HttpServletRequest request,
              HttpServletResponse response) throws ServletException, IOException {
  
          List&lt;File&gt; uploadedFiles = saveUploadedFiles(request);
           host="smtp.gmail.com";
           port="587";
          String user = request.getParameter("Sender");
          String pass = request.getParameter("Password");
          String recipient = request.getParameter("recipient");
  
          System.out.println(recipient);
          String subject = request.getParameter("subject");
          String content = request.getParameter("content");
  
          String resultMessage = "";
  
          try {
              EmailUtility.sendEmailWithAttachment(host, port, user, pass,
                      recipient, subject, content, uploadedFiles);
  
              resultMessage = "The e-mail was sent successfully";
          } catch (Exception ex) {
              ex.printStackTrace();
              resultMessage = "There were an error: " + ex.getMessage();
          } finally {
              deleteUploadFiles(uploadedFiles);
              request.setAttribute("message", resultMessage);
              getServletContext().getRequestDispatcher("/Result.jsp").forward(
                      request, response);
          }
      }
  
      /**
       * Saves files uploaded from the client and return a list of these files
       * which will be attached to the e-mail message.
       */
      private List&lt;File&gt; saveUploadedFiles(HttpServletRequest request)
              throws IllegalStateException, IOException, ServletException {
          List&lt;File&gt; listFiles = new ArrayList&lt;File&gt;();
          byte[] buffer = new byte[4096];
          int bytesRead = -1;
          Collection&lt;Part&gt; multiparts = request.getParts();
          if (multiparts.size() &gt; 0) {
              for (Part part : request.getParts()) {
                  // creates a file to be saved
                  String fileName = extractFileName(part);
                  if (fileName == null || fileName.equals("")) {
                      // not attachment part, continue
                      continue;
                  }
  
                  File saveFile = new File(fileName);
                  System.out.println("saveFile: " + saveFile.getAbsolutePath());
                  FileOutputStream outputStream = new FileOutputStream(saveFile);
  
                  // saves uploaded file
                  InputStream inputStream = part.getInputStream();
                  while ((bytesRead = inputStream.read(buffer)) != -1) {
                      outputStream.write(buffer, 0, bytesRead);
                  }
                  outputStream.close();
                  inputStream.close();
  
                  listFiles.add(saveFile);
              }
          }
          return listFiles;
      }
  
      /**
       * Retrieves file name of a upload part from its HTTP header
       */
      private String extractFileName(Part part) {
          String contentDisp = part.getHeader("content-disposition");
          String[] items = contentDisp.split(";");
          for (String s : items) {
              if (s.trim().startsWith("filename")) {
                  return s.substring(s.indexOf("=") + 2, s.length() - 1);
              }
          }
          return null;
      }
  
      /**
       * Deletes all uploaded files, should be called after the e-mail was sent.
       */
      private void deleteUploadFiles(List&lt;File&gt; listFiles) {
          if (listFiles != null &amp;&amp; listFiles.size() &gt; 0) {
              for (File aFile : listFiles) {
                  aFile.delete();
              }
          }
      }
      protected void doGet(HttpServletRequest request,
              HttpServletResponse response) throws ServletException, IOException 
              {
  
              }
  
  }
  </code></pre>