final String toAddress, final List<FileItem> files) {
Properties props = new Properties();
Session session = Session.getDefaultInstance(props, null);
try {
Multipart mp = new MimeMultipart();
MimeBodyPart htmlPart = new MimeBodyPart();
htmlPart.setContent(htmlBody, "text/html");
htmlPart.setHeader("Content-type", "text/html; charset=UTF-8");
mp.addBodyPart(htmlPart);
for (FileItem item : files) {
MimeBodyPart attachment = new MimeBodyPart();
attachment.setFileName(item.getFilename());
String mimeType = MimeType.getContentTypeByExt(
FolderUtil.getFileExt(item.getFilename()));
DataSource ds = new ByteArrayDataSource(item.getData(), mimeType);
attachment.setDataHandler(new DataHandler(ds));
mp.addBodyPart(attachment);
}
MimeMessage msg = new MimeMessage(session);
msg.setFrom(new InternetAddress(fromAddress, fromText));
msg.addRecipient(Message.RecipientType.TO,
new InternetAddress(toAddress, toAddress));