List of usage examples for org.springframework.mail.javamail MimeMessageHelper getFileTypeMap
public FileTypeMap getFileTypeMap()
From source file:org.rill.bpm.common.mail.support.TemplateMailSenderSupport.java
@SuppressWarnings("unchecked") protected MimeMessageHelper processMultipart(Map<String, Object> model, MimeMessageHelper messageHelper) throws MessagingException { // Handle multipart if (isMultipart(model)) { List<AttachmentWarper> list = new ArrayList<AttachmentWarper>(); Object attachments = model.get(TemplateMailSender.ATTACHMENT_KEY); if (attachments.getClass().isArray()) { AttachmentWarper[] awArrays = ((AttachmentWarper[]) attachments); list.addAll(Arrays.asList(awArrays)); } else if (attachments instanceof Collection) { Collection<AttachmentWarper> c = (Collection<AttachmentWarper>) attachments; list.addAll(c);/* ww w .ja va2 s.co m*/ } else { list.add(((AttachmentWarper) attachments)); } for (AttachmentWarper aw : list) { if (aw.getContentType() == null) messageHelper.addAttachment(aw.getAttachmentFileName(), aw.getInputStreamSource()); else messageHelper.addAttachment(aw.getAttachmentFileName(), aw.getInputStreamSource(), aw.getContentType()); } } // Handle multipart if (isMultipart(model)) { List<AttachmentWarper> list = new ArrayList<AttachmentWarper>(); Object inline = model.get(TemplateMailSender.INLINE_KEY); if (inline.getClass().isArray()) { AttachmentWarper[] awArrays = ((AttachmentWarper[]) inline); list.addAll(Arrays.asList(awArrays)); } else if (inline instanceof Collection) { Collection<AttachmentWarper> c = (Collection<AttachmentWarper>) inline; list.addAll(c); } else { list.add(((AttachmentWarper) inline)); } for (AttachmentWarper aw : list) { String cid = StringUtils.replace(aw.getAttachmentFileName(), ".", "_"); if (aw.getContentType() == null) messageHelper.addInline(cid, aw.getInputStreamSource(), messageHelper.getFileTypeMap().getContentType(aw.getAttachmentFileName())); else messageHelper.addInline(cid, aw.getInputStreamSource(), aw.getContentType()); } } return messageHelper; }