if (attachments != null && attachments.isEmpty() == false) {
// create an Array of message parts for Attachments
final MimeBodyPart mbp[] = new MimeBodyPart[attachments.size()];
// remember you can extend this functionality with META-INF/mime.types
// See http://docs.oracle.com/javaee/5/api/javax/activation/MimetypesFileTypeMap.html
final MimetypesFileTypeMap mimeTypesMap = new MimetypesFileTypeMap();
int i=0;
for (final MailAttachment attachment: attachments) {
// create the next message part
mbp[i] = new MimeBodyPart();
// only by file name
String mimeType = mimeTypesMap.getContentType(attachment.getFilename());
if (StringUtils.isBlank(mimeType)) {
mimeType = "application/octet-stream";
}
// attach the file to the message
final DataSource ds=