title: How to send table or View as embedded HTML <table> in an email
body: <p>I have tried to send html table through java code</p>
  
  <pre><code>    public static void main(String args[]){
              try{
              Properties props = new Properties();
              props.setProperty("mail.transport.protocol", "smtp");
              props.setProperty("mail.host", "smtp.gmail.com");
  
              Session mailSession = Session.getDefaultInstance(props, null);
              mailSession.setDebug(true);
              Transport transport = mailSession.getTransport();
  
              MimeMessage message = new MimeMessage(mailSession);
              message.setSubject("HTML  mail with images");
              message.setFrom(new InternetAddress("abc@gmail.com"));
              message.addRecipient(Message.RecipientType.TO,
                   new InternetAddress("abc@gmail.com"));
  
              String html = "&lt;html&gt;&lt;head&gt;&lt;title&gt;" +
              message.getSubject() +
              "&lt;/title&gt;&lt;/head&gt;&lt;body&gt;&lt;h1&gt;" +
              message.getSubject() +
              "&lt;/h1&gt;&lt;p&gt;This is a test of sending an HTML e-mail" +
              " through Java.&lt;/p&gt;";
  
  // HTMLDataSource is an inner class
              message.setDataHandler(new DataHandler(new HTMLDataSource(html)));
  
              transport.connect();
              transport.sendMessage(message,
                  message.getRecipients(Message.RecipientType.TO));
              transport.close();
              }
              catch(Exception e)
              {
                  e.printStackTrace();
              }
              }
          static class HTMLDataSource implements DataSource {
              private String html;
  
              public HTMLDataSource(String htmlString) {
                  html = htmlString;
              }
  
              // Return html string in an InputStream.
              // A new stream must be returned each time.
              public InputStream getInputStream() throws IOException {
                  if (html == null) throw new IOException("Null HTML");
                  return new ByteArrayInputStream(html.getBytes());
              }
  
              public OutputStream getOutputStream() throws IOException {
                  throw new IOException("This DataHandler cannot write HTML");
              }
  
              public String getContentType() {
                  return "text/html";
              }
  
              public String getName() {
                  return "JAF text/html dataSource to send e-mail only";
              }
          }
      }
  </code></pre>
  
  <p>I have stored table data in ArrayList in the separate class.Below is the snippet of it.</p>
  
  <pre><code>List objList = new ArrayList();
      try
      {
          conn=dao.DBConnection();
  
          sql1.append(" select MENU_ID, MENU_CODE, MENU_NAME, DESCRIPTON, ACTION_URL, CATEGORY, SORT_ORDER from m_menus order by MENU_ID ");
  
  
          iPreparedStatement1=conn.prepareStatement(sql1.toString());
          iResultSet1=iPreparedStatement1.executeQuery();
  
          while(iResultSet1.next())
          {
              afUserAdminMenuMaster objafuseradminmenumaster = new afUserAdminMenuMaster();
              Integer i=0;
  
              objafuseradminmenumaster.setMenuId(iResultSet1.getString(++i));
              objafuseradminmenumaster.setMenuCode(iResultSet1.getString(++i));
              objafuseradminmenumaster.setMenuName(iResultSet1.getString(++i));
              objafuseradminmenumaster.setMenuDesc(iResultSet1.getString(++i));
              objafuseradminmenumaster.setAction_URL(iResultSet1.getString(++i));
              objafuseradminmenumaster.setCategory(iResultSet1.getString(++i));
              objafuseradminmenumaster.setSortOrder(iResultSet1.getString(++i));
  
  
              objList.add(objafuseradminmenumaster);
          }
  </code></pre>
  
  <p>I want to embed that sql table in the mail body which will be dynamic depending on the condition.Please guide how should I proceed.</p>