use of org.subethamail.wiser.WiserMessage in project Activiti by Activiti.
the class EmailSendTaskTest method testTextMailWithFileAttachment.
@Deployment
public void testTextMailWithFileAttachment() throws Exception {
HashMap<String, Object> vars = new HashMap<String, Object>();
vars.put("attachmentsBean", new AttachmentsBean());
runtimeService.startProcessInstanceByKey("textMailWithFileAttachment", vars);
List<WiserMessage> messages = wiser.getMessages();
assertEquals(1, messages.size());
WiserMessage message = messages.get(0);
MimeMultipart mm = (MimeMultipart) message.getMimeMessage().getContent();
assertEquals(2, mm.getCount());
String attachmentFileName = mm.getBodyPart(1).getDataHandler().getName();
assertEquals(new AttachmentsBean().getFile().getName(), attachmentFileName);
}
use of org.subethamail.wiser.WiserMessage in project Activiti by Activiti.
the class EmailSendTaskTest method testTextMailWithDataSourceAttachment.
@Deployment
public void testTextMailWithDataSourceAttachment() throws Exception {
String fileName = "file-name-to-be-displayed";
String fileContent = "This is the file content";
HashMap<String, Object> vars = new HashMap<String, Object>();
vars.put("attachmentsBean", new AttachmentsBean());
vars.put("fileContent", fileContent);
vars.put("fileName", fileName);
runtimeService.startProcessInstanceByKey("textMailWithDataSourceAttachment", vars);
List<WiserMessage> messages = wiser.getMessages();
assertEquals(1, messages.size());
WiserMessage message = messages.get(0);
MimeMultipart mm = (MimeMultipart) message.getMimeMessage().getContent();
assertEquals(2, mm.getCount());
String attachmentFileName = mm.getBodyPart(1).getDataHandler().getName();
assertEquals(fileName, attachmentFileName);
}
use of org.subethamail.wiser.WiserMessage in project Activiti by Activiti.
the class EmailSendTaskTest method testHtmlMailWithFileAttachment.
@Deployment
public void testHtmlMailWithFileAttachment() throws Exception {
HashMap<String, Object> vars = new HashMap<String, Object>();
vars.put("attachmentsBean", new AttachmentsBean());
vars.put("gender", "male");
runtimeService.startProcessInstanceByKey("htmlMailWithFileAttachment", vars);
List<WiserMessage> messages = wiser.getMessages();
assertEquals(1, messages.size());
WiserMessage message = messages.get(0);
MimeMultipart mm = (MimeMultipart) message.getMimeMessage().getContent();
assertEquals(2, mm.getCount());
String attachmentFileName = mm.getBodyPart(1).getDataHandler().getName();
assertEquals(new AttachmentsBean().getFile().getName(), attachmentFileName);
}
use of org.subethamail.wiser.WiserMessage in project spring-integration-samples by spring-projects.
the class MimeMessageParsingTest method testProcessingOfEmailAttachments.
/**
* This test will create a Mime Message that contains an Attachment, send it
* to an SMTP Server (Using Wiser) and retrieve and process the Mime Message.
*
* This test verifies that the parsing of the retrieved Mime Message is
* successful and that the correct number of {@link EmailFragment}s is created.
*/
@Test
public void testProcessingOfEmailAttachments() {
final JavaMailSenderImpl mailSender = new JavaMailSenderImpl();
mailSender.setPort(this.wiserPort);
final MimeMessage message = mailSender.createMimeMessage();
final String pictureName = "picture.png";
final ByteArrayResource byteArrayResource = getFileData(pictureName);
try {
final MimeMessageHelper helper = new MimeMessageHelper(message, true);
helper.setFrom("testfrom@springintegration.org");
helper.setTo("testto@springintegration.org");
helper.setSubject("Parsing of Attachments");
helper.setText("Spring Integration Rocks!");
helper.addAttachment(pictureName, byteArrayResource, "image/png");
} catch (MessagingException e) {
throw new MailParseException(e);
}
mailSender.send(message);
final List<WiserMessage> wiserMessages = wiser.getMessages();
Assert.assertTrue(wiserMessages.size() == 1);
boolean foundTextMessage = false;
boolean foundPicture = false;
for (WiserMessage wiserMessage : wiserMessages) {
final List<EmailFragment> emailFragments = new ArrayList<EmailFragment>();
try {
final MimeMessage mailMessage = wiserMessage.getMimeMessage();
EmailParserUtils.handleMessage(null, mailMessage, emailFragments);
} catch (MessagingException e) {
throw new IllegalStateException("Error while retrieving Mime Message.");
}
Assert.assertTrue(emailFragments.size() == 2);
for (EmailFragment emailFragment : emailFragments) {
if ("picture.png".equals(emailFragment.getFilename())) {
foundPicture = true;
}
if ("message.txt".equals(emailFragment.getFilename())) {
foundTextMessage = true;
}
}
Assert.assertTrue(foundPicture);
Assert.assertTrue(foundTextMessage);
}
}
use of org.subethamail.wiser.WiserMessage in project motech by motech.
the class EmailBundleIT method testEmailService.
@Test
public void testEmailService() throws MessagingException, IOException, EmailSendException {
ClassLoader oldCl = Thread.currentThread().getContextClassLoader();
try {
Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
mailService.send("from@from.com", "to@to.com", "test", "test");
} finally {
Thread.currentThread().setContextClassLoader(oldCl);
}
WiserMessage message = smtpServer.getMessages().get(0);
String msgTxt = (String) message.getMimeMessage().getContent();
assertNotNull(msgTxt);
assertEquals("test", msgTxt.trim());
}
Aggregations