List of usage examples for javax.mail BodyPart setDescription
public void setDescription(String description) throws MessagingException;
From source file:org.jahia.services.workflow.jbpm.custom.email.JBPMMailProducer.java
protected void addAttachments(MailTemplate template, WorkItem workItem, Multipart multipart, JCRSessionWrapper session) throws Exception { for (AttachmentTemplate attachmentTemplate : template.getAttachmentTemplates()) { BodyPart attachmentPart = new MimeBodyPart(); // resolve description String description = attachmentTemplate.getDescription(); if (description != null) { attachmentPart.setDescription(evaluateExpression(workItem, description, session)); }/*from w ww . ja v a2 s .c om*/ // obtain interface to data DataHandler dataHandler = createDataHandler(attachmentTemplate, workItem, session); attachmentPart.setDataHandler(dataHandler); // resolve file name String name = attachmentTemplate.getName(); if (name != null) { attachmentPart.setFileName(evaluateExpression(workItem, name, session)); } else { // fall back on data source DataSource dataSource = dataHandler.getDataSource(); if (dataSource instanceof URLDataSource) { name = extractResourceName(((URLDataSource) dataSource).getURL()); } else { name = dataSource.getName(); } if (name != null) { attachmentPart.setFileName(name); } } multipart.addBodyPart(attachmentPart); } }
From source file:org.mule.transport.email.transformers.ObjectToMimeMessage.java
protected BodyPart getBodyPartForAttachment(DataHandler handler, String name) throws MessagingException { BodyPart part = new MimeBodyPart(); part.setDataHandler(handler);//www . java2 s . c o m part.setDescription(name); part.setFileName(StringUtils.defaultString(handler.getName(), name)); return part; }
From source file:org.mule.transport.email.transformers.ObjectToMimeMessage.java
protected BodyPart getPayloadBodyPart(Object payload, String contentType) throws MessagingException, TransformerException, IOException { DataHandler handler;/* w w w . ja va 2 s.c o m*/ if (payload instanceof String) { handler = new DataHandler(new ByteArrayDataSource((String) payload, contentType)); } else if (payload instanceof byte[]) { handler = new DataHandler(new ByteArrayDataSource((byte[]) payload, contentType)); } else if (payload instanceof Serializable) { handler = new DataHandler(new ByteArrayDataSource( (byte[]) new SerializableToByteArray().transform(payload), contentType)); } else { throw new IllegalArgumentException(); } BodyPart part = new MimeBodyPart(); part.setDataHandler(handler); part.setDescription("Payload"); return part; }