sending a excel in an attachment in email java
Java
ByteArrayOutputStream bos = new ByteArrayOutputStream();
xlsFile.write(bos); // write excel data to a byte array
fos.close();
// Now use your ByteArrayDataSource as
DataSource fds = new ByteArrayDataSource(bos.toByteArray(), "application/vnd.ms-excel"); // Define message
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress(from));
message.addRecipient(Message.RecipientType.TO,
new InternetAddress(to));
message.setSubject("Hello JavaMail Attachment");
// Create the message part
BodyPart messageBodyPart = new MimeBodyPart();
// Fill the message
messageBodyPart.setText("Pardon Ideas");
Multipart multipart = new MimeMultipart();
multipart.addBodyPart(messageBodyPart);
// Part two is attachment
messageBodyPart = new MimeBodyPart();
DataSource source = new FileDataSource(filename);
messageBodyPart.setDataHandler(new DataHandler(source));
messageBodyPart.setFileName(filename);
multipart.addBodyPart(messageBodyPart);
// Put parts in message
message.setContent(multipart);
// Send the message
Transport.send(message);Workbook xlsFile = new HSSFWorkbook(); // create a workbook
CreationHelper helper = xlsFile.getCreationHelper();
Sheet sheet1 = xlsFile.createSheet("Sheet #1"); // add a sheet to your workbook
while(rs.next())
{
Row row = sheet1.createRow((short)0); // create a new row in your sheet
for(int i = 0; i < 12; i++)
{
row.createCell(i).setCellValue(
helper.createRichTextString(exceldata)); // add cells to the row
}
}
// Write the output to a temporary excel file
FileOutputStream fos = new FileOutputStream("temp.xls");
xlsFile.write(fos);
fos.close();
// Switch to using a `FileDataSource` (instead of ByteArrayDataSource)
DataSource fds = new FileDataSource("temp.xls");
Also in Java:
- Title
- how to make a dictionary in java
- Category
- Java
- Title
- java how to get current date
- Category
- Java
- Title
- ndroid.support.v4.content.FileProvider
- Category
- Java
- Title
- kotlin add value to MutableLiveData
- Category
- Java
- Title
- Java Read Files
- Category
- Java
- Title
- create object of static class in java
- Category
- Java
- Title
- validate isbn number java
- Category
- Java
- Title
- how to return the lower of two values in one line java
- Category
- Java
- Title
- log4j with spring boot restful services
- Category
- Java
- Title
- java loop through array
- Category
- Java
- Title
- java replaceall single character
- Category
- Java
- Title
- objectoutputstream exemple
- Category
- Java
- Title
- Primitive Type vs. Reference Type
- Category
- Java
- Title
- cordova cannot find symbol import com.google.firebase.iid.FirebaseMessagingService;
- Category
- Java
- Title
- Matlab java.lang.IllegalArgumentException: Invalid range
- Category
- Java
- Title
- java string to lower case
- Category
- Java
- Title
- how to check if the file has remaining without reading from it java
- Category
- Java
- Title
- how to draw a triangle in java
- Category
- Java
- Title
- convert string to array java
- Category
- Java
- Title
- java how to show an array
- Category
- Java
- Title
- java min function
- Category
- Java
- Title
- rgb to hex java
- Category
- Java
- Title
- Java nested array hashcode
- Category
- Java
- Title
- read csv java android
- Category
- Java
- Title
- compile java to jar in mac
- Category
- Java
- Title
- mutable string in java
- Category
- Java
- Title
- how to input in java
- Category
- Java
- Title
- sum of arraylist java 8
- Category
- Java
- Title
- import collections in java
- Category
- Java
- Title
- get random number from enum in java
- Category
- Java
- Title
- linux pyspark select java version
- Category
- Java
- Title
- android round double to 2 decimal
- Category
- Java
- Title
- iterate map in java 8 using stream
- Category
- Java
- Title
- how to fill a 2d array in java
- Category
- Java
- Title
- how to select a element in an arraylist java
- Category
- Java
- Title
- parsedouble java
- Category
- Java
- Title
- remove unused imports intellij
- Category
- Java
- Title
- java implement interface
- Category
- Java
- Title
- write an infinite loop java
- Category
- Java
- Title
- java catch multiple exceptions
- Category
- Java
- Title
- how to print array in java using for loop
- Category
- Java
- Title
- java binary exponentiation
- Category
- Java
- Title
- eliminar fila jtable java
- Category
- Java
- Title
- java Convert a string IPv4 IP address to the equivalent long numeric value.
- Category
- Java
- Title
- jsonobject to java object
- Category
- Java
- Title
- java 8 stream group by example
- Category
- Java
- Title
- java string to uuid
- Category
- Java
- Title
- if else program in java
- Category
- Java
- Title
- labeled for loop in java
- Category
- Java
- Title
- java how to call getReader twice
- Category
- Java
- Title
- how to print to console in java
- Category
- Java
- Title
- how to delete character in string java
- Category
- Java
- Title
- how lock horizontal orientation android
- Category
- Java
- Title
- indexof java
- Category
- Java
- Title
- how to add two map values in java
- Category
- Java
- Title
- public static void main(string args)
- Category
- Java
- Title
- java method to capitalize first letter
- Category
- Java
- Title
- math minimum java
- Category
- Java
- Title
- méthode retourne nom classe java
- Category
- Java
- Title
- how to create a java jframe
- Category
- Java
- Title
- substring java
- Category
- Java
- Title
- set color of text for jlabel
- Category
- Java
- Title
- android java how to stop users fromgoing back too much
- Category
- Java
- Title
- android java retrofit offline cache
- Category
- Java
- Title
- log4j print stacktrace
- Category
- Java
- Title
- java.lang.ClassCastException: cannot be cast to javax.servlet.Servlet
- Category
- Java
- Title
- Filebody in java
- Category
- Java
- Title
- java 8 map foreach
- Category
- Java
- Title
- comparable on a generic class java
- Category
- Java
- Title
- properties java 8 maven in pom xml
- Category
- Java
- Title
- 2 decimal places print format JAVA
- Category
- Java
- Title
- java iterator example
- Category
- Java
- Title
- place.getlatlng() returning null
- Category
- Java
- Title
- alfred workflow
- Category
- Java
- Title
- how to make an object move with arrow keys in java
- Category
- Java
- Title
- string remove last character
- Category
- Java
- Title
- java program to find prime number between 1 and 100
- Category
- Java
- Title
- while loop java
- Category
- Java
- Title
- how to add an image to a gui in java windowbuilder
- Category
- Java
- Title
- replace all punctuation in string java
- Category
- Java
- Title
- how to create an action listener in java
- Category
- Java
- Title
- reverse string using recursion java with explanation
- Category
- Java
- Title
- iterate map in java
- Category
- Java
- Title
- java nested loop
- Category
- Java
- Title
- try block in java
- Category
- Java
- Title
- count word in string no matter the delimiter java
- Category
- Java
- Title
- how to end a program in an if statement java
- Category
- Java
- Title
- convert every character in string to arraylist jva
- Category
- Java
- Title
- how to play an audio in java
- Category
- Java
- Title
- java 8 list stream delete by name
- Category
- Java
- Title
- listview get selected java
- Category
- Java
- Title
- string replace last character java
- Category
- Java
- Title
- spigot cancel repeating task
- Category
- Java
- Title
- java random boolean
- Category
- Java
- Title
- priority queue in java
- Category
- Java
- Title
- jstl core tags
- Category
- Java
- Title
- How to make a class in Java?
- Category
- Java
- Title
- java 8 iterating and manipulating list
- Category
- Java
- Title
- recursion in java
- Category
- Java
- Title
- open an existing excel file in java apache poi
- Category
- Java