java mimemessage attachment code example
Example 1: sending a excel in an attachment in email java
Workbook xlsFile = new HSSFWorkbook();
CreationHelper helper = xlsFile.getCreationHelper();
Sheet sheet1 = xlsFile.createSheet("Sheet #1");
while(rs.next())
{
Row row = sheet1.createRow((short)0);
for(int i = 0; i < 12; i++)
{
row.createCell(i).setCellValue(
helper.createRichTextString(exceldata));
}
}
FileOutputStream fos = new FileOutputStream("temp.xls");
xlsFile.write(fos);
fos.close();
DataSource fds = new FileDataSource("temp.xls");
Example 2: sending a excel in an attachment in email java
ByteArrayOutputStream bos = new ByteArrayOutputStream();
xlsFile.write(bos);
fos.close();
DataSource fds = new ByteArrayDataSource(bos.toByteArray(), "application/vnd.ms-excel");