use of javax.activation.DataSource in project jbpm-work-items by kiegroup.
the class SendMailWorkitemHandler method createEmailWithAttachment.
public MimeMessage createEmailWithAttachment(String to, String from, String subject, String bodyText, Document attachment) throws MessagingException, IOException {
Properties props = new Properties();
Session session = Session.getDefaultInstance(props, null);
MimeMessage email = new MimeMessage(session);
email.setFrom(new InternetAddress(from));
email.addRecipient(javax.mail.Message.RecipientType.TO, new InternetAddress(to));
email.setSubject(subject);
MimeBodyPart mimeBodyPart = new MimeBodyPart();
mimeBodyPart.setContent(bodyText, "text/plain");
Multipart multipart = new MimeMultipart();
multipart.addBodyPart(mimeBodyPart);
if (attachment != null) {
mimeBodyPart = new MimeBodyPart();
DataSource source = new InputStreamDataSource(new ByteArrayInputStream(attachment.getContent()));
mimeBodyPart.setDataHandler(new DataHandler(source));
mimeBodyPart.setFileName(attachment.getName());
multipart.addBodyPart(mimeBodyPart);
}
email.setContent(multipart);
return email;
}
use of javax.activation.DataSource in project simple-java-mail by bbottema.
the class NamedDataSourceTest method contentTypeStreamWillBeTheSame1.
@Test
public void contentTypeStreamWillBeTheSame1() throws Exception {
DataSource testDataSource = new NamedDataSource("newName", dataSource);
testDataSource.getContentType();
verify(dataSource).getContentType();
}
use of javax.activation.DataSource in project simple-java-mail by bbottema.
the class NamedDataSourceTest method renameWillWork.
@Test
public void renameWillWork() throws Exception {
DataSource testDataSource = new NamedDataSource("newName", dataSource);
assertThat(testDataSource.getName()).isEqualTo("newName");
verifyZeroInteractions(dataSource);
}
use of javax.activation.DataSource in project simple-java-mail by bbottema.
the class NamedDataSourceTest method outputStreamWillBeTheSame1.
@Test
public void outputStreamWillBeTheSame1() throws Exception {
DataSource testDataSource = new NamedDataSource("newName", dataSource);
testDataSource.getOutputStream();
verify(dataSource).getOutputStream();
}
use of javax.activation.DataSource in project simple-java-mail by bbottema.
the class MimeMessageParser method createDataSource.
/**
* Parses the MimePart to create a DataSource.
*
* @param part the current part to be processed
* @return the DataSource
*/
@Nonnull
private static DataSource createDataSource(@Nonnull final MimePart part) {
final DataHandler dataHandler = retrieveDataHandler(part);
final DataSource dataSource = dataHandler.getDataSource();
final String contentType = parseBaseMimeType(dataSource.getContentType());
final byte[] content = readContent(retrieveInputStream(dataSource));
final ByteArrayDataSource result = new ByteArrayDataSource(content, contentType);
final String dataSourceName = parseDataSourceName(part, dataSource);
result.setName(dataSourceName);
return result;
}
Aggregations