Java Code Examples for org.subethamail.wiser.WiserMessage#getMimeMessage()
The following examples show how to use
org.subethamail.wiser.WiserMessage#getMimeMessage() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MailerImplTest.java From quarkus with Apache License 2.0 | 6 votes |
@Test void testAttachmentsLegacy() throws MessagingException, IOException { legacyMailer.send(Mail.withText(TO, "Test", "Simple Test") .addAttachment("some-data.txt", "Hello".getBytes(StandardCharsets.UTF_8), TEXT_CONTENT_TYPE) .addAttachment("some-data-2.txt", "Hello 2".getBytes(StandardCharsets.UTF_8), TEXT_CONTENT_TYPE)) .toCompletableFuture().join(); assertThat(wiser.getMessages()).hasSize(1); WiserMessage actual = wiser.getMessages().get(0); assertThat(getContent(actual)).contains("Simple Test"); MimeMessage msg = actual.getMimeMessage(); assertThat(msg.getSubject()).isEqualTo("Test"); assertThat(msg.getFrom()[0].toString()).isEqualTo(FROM); String value = getAttachment("some-data.txt", (MimeMultipart) actual.getMimeMessage().getContent()); assertThat(value).isEqualTo("Hello"); value = getAttachment("some-data-2.txt", (MimeMultipart) actual.getMimeMessage().getContent()); assertThat(value).isEqualTo("Hello 2"); }
Example 2
Source File: MailerImplTest.java From quarkus with Apache License 2.0 | 6 votes |
@Test void testAttachments() throws MessagingException, IOException { mailer.send(Mail.withText(TO, "Test", "Simple Test") .addAttachment("some-data.txt", "Hello".getBytes(StandardCharsets.UTF_8), TEXT_CONTENT_TYPE) .addAttachment("some-data-2.txt", "Hello 2".getBytes(StandardCharsets.UTF_8), TEXT_CONTENT_TYPE)) .await().indefinitely(); assertThat(wiser.getMessages()).hasSize(1); WiserMessage actual = wiser.getMessages().get(0); assertThat(getContent(actual)).contains("Simple Test"); MimeMessage msg = actual.getMimeMessage(); assertThat(msg.getSubject()).isEqualTo("Test"); assertThat(msg.getFrom()[0].toString()).isEqualTo(FROM); String value = getAttachment("some-data.txt", (MimeMultipart) actual.getMimeMessage().getContent()); assertThat(value).isEqualTo("Hello"); value = getAttachment("some-data-2.txt", (MimeMultipart) actual.getMimeMessage().getContent()); assertThat(value).isEqualTo("Hello 2"); }
Example 3
Source File: MailerImplTest.java From quarkus with Apache License 2.0 | 6 votes |
@Test void testInlineAttachment() throws MessagingException, IOException { String cid = UUID.randomUUID().toString() + "@acme"; mailer.send(Mail.withHtml(TO, "Test", "testInlineAttachment") .addInlineAttachment("inline.txt", "my inlined text".getBytes(StandardCharsets.UTF_8), TEXT_CONTENT_TYPE, cid)) .await().indefinitely(); assertThat(wiser.getMessages()).hasSize(1); WiserMessage actual = wiser.getMessages().get(0); assertThat(getContent(actual)).contains("testInlineAttachment"); MimeMessage msg = actual.getMimeMessage(); assertThat(msg.getSubject()).isEqualTo("Test"); assertThat(msg.getFrom()[0].toString()).isEqualTo(FROM); String value = getInlineAttachment("<" + cid + ">", (MimeMultipart) actual.getMimeMessage().getContent()); assertThat(value).isEqualTo("my inlined text"); }
Example 4
Source File: EmailSendTaskTest.java From activiti6-boot2 with Apache License 2.0 | 5 votes |
private void assertEmailSend(WiserMessage emailMessage, boolean htmlMail, String subject, String message, String from, List<String> to, List<String> cc) throws IOException { try { MimeMessage mimeMessage = emailMessage.getMimeMessage(); if (htmlMail) { assertTrue(mimeMessage.getContentType().contains("multipart/mixed")); } else { assertTrue(mimeMessage.getContentType().contains("text/plain")); } assertEquals(subject, mimeMessage.getHeader("Subject", null)); assertEquals(from, mimeMessage.getHeader("From", null)); assertTrue(getMessage(mimeMessage).contains(message)); for (String t : to) { assertTrue(mimeMessage.getHeader("To", null).contains(t)); } if (cc != null) { for (String c : cc) { assertTrue(mimeMessage.getHeader("Cc", null).contains(c)); } } } catch (MessagingException e) { fail(e.getMessage()); } }
Example 5
Source File: MailerImplTest.java From quarkus with Apache License 2.0 | 5 votes |
@Test void testTextMail() throws MessagingException, IOException { String content = UUID.randomUUID().toString(); mailer.send(Mail.withText(TO, "Test", content)).await().indefinitely(); assertThat(wiser.getMessages()).hasSize(1); WiserMessage actual = wiser.getMessages().get(0); assertThat(getContent(actual)).contains(content); MimeMessage msg = actual.getMimeMessage(); List<String> types = getContentTypesFromMimeMultipart((MimeMultipart) actual.getMimeMessage().getContent()); assertThat(types).containsExactly(TEXT_CONTENT_TYPE); assertThat(msg.getSubject()).isEqualTo("Test"); assertThat(msg.getFrom()[0].toString()).isEqualTo(FROM); assertThat(msg.getAllRecipients()).hasSize(1).contains(new InternetAddress(TO)); }
Example 6
Source File: EmailServiceTaskTest.java From activiti6-boot2 with Apache License 2.0 | 5 votes |
@Deployment public void testSendEmail() throws Exception { String from = "[email protected]"; boolean male = true; String recipientName = "John Doe"; String recipient = "[email protected]"; Date now = new Date(); String orderId = "123456"; Map<String, Object> vars = new HashMap<String, Object>(); vars.put("sender", from); vars.put("recipient", recipient); vars.put("recipientName", recipientName); vars.put("male", male); vars.put("now", now); vars.put("orderId", orderId); runtimeService.startProcessInstanceByKey("sendMailExample", vars); List<WiserMessage> messages = wiser.getMessages(); assertEquals(1, messages.size()); WiserMessage message = messages.get(0); MimeMessage mimeMessage = message.getMimeMessage(); assertEquals("Your order " + orderId + " has been shipped", mimeMessage.getHeader("Subject", null)); assertEquals(from, mimeMessage.getHeader("From", null)); assertTrue(mimeMessage.getHeader("To", null).contains(recipient)); }
Example 7
Source File: EmailSendTaskTest.java From activiti6-boot2 with Apache License 2.0 | 5 votes |
@Deployment public void testSendEmail() throws Exception { String from = "[email protected]"; boolean male = true; String recipientName = "John Doe"; String recipient = "[email protected]"; Date now = new Date(); String orderId = "123456"; Map<String, Object> vars = new HashMap<String, Object>(); vars.put("sender", from); vars.put("recipient", recipient); vars.put("recipientName", recipientName); vars.put("male", male); vars.put("now", now); vars.put("orderId", orderId); runtimeService.startProcessInstanceByKey("sendMailExample", vars); List<WiserMessage> messages = wiser.getMessages(); assertEquals(1, messages.size()); WiserMessage message = messages.get(0); MimeMessage mimeMessage = message.getMimeMessage(); assertEquals("Your order " + orderId + " has been shipped", mimeMessage.getHeader("Subject", null)); assertEquals(from, mimeMessage.getHeader("From", null)); assertTrue(mimeMessage.getHeader("To", null).contains(recipient)); }
Example 8
Source File: EmailServiceTaskTest.java From activiti6-boot2 with Apache License 2.0 | 5 votes |
@Deployment public void testSendEmail() throws Exception { String from = "[email protected]"; boolean male = true; String recipientName = "John Doe"; String recipient = "[email protected]"; Date now = new Date(); String orderId = "123456"; Map<String, Object> vars = new HashMap<String, Object>(); vars.put("sender", from); vars.put("recipient", recipient); vars.put("recipientName", recipientName); vars.put("male", male); vars.put("now", now); vars.put("orderId", orderId); runtimeService.startProcessInstanceByKey("sendMailExample", vars); List<WiserMessage> messages = wiser.getMessages(); assertEquals(1, messages.size()); WiserMessage message = messages.get(0); MimeMessage mimeMessage = message.getMimeMessage(); assertEquals("Your order " + orderId + " has been shipped", mimeMessage.getHeader("Subject", null)); assertEquals(from, mimeMessage.getHeader("From", null)); assertTrue(mimeMessage.getHeader("To", null).contains(recipient)); }
Example 9
Source File: MailerImplTest.java From quarkus with Apache License 2.0 | 5 votes |
@Test void testReplyToHeaderIsSetLegacy() throws MessagingException { legacyMailer.send(Mail.withText(TO, "Test", "testHeaders") .setReplyTo("[email protected]")) .toCompletableFuture().join(); assertThat(wiser.getMessages()).hasSize(1); WiserMessage actual = wiser.getMessages().get(0); MimeMessage msg = actual.getMimeMessage(); assertThat(msg.getHeader("Reply-To")).containsExactly("[email protected]"); assertThat(msg.getReplyTo()).containsExactly(InternetAddress.parse("[email protected]")); }
Example 10
Source File: MailerImplTest.java From quarkus with Apache License 2.0 | 5 votes |
@Test void testReplyToHeaderIsSet() throws MessagingException { mailer.send(Mail.withText(TO, "Test", "testHeaders") .setReplyTo("[email protected]")) .await().indefinitely(); assertThat(wiser.getMessages()).hasSize(1); WiserMessage actual = wiser.getMessages().get(0); MimeMessage msg = actual.getMimeMessage(); assertThat(msg.getHeader("Reply-To")).containsExactly("[email protected]"); assertThat(msg.getReplyTo()).containsExactly(InternetAddress.parse("[email protected]")); }
Example 11
Source File: EmailServiceTaskTest.java From activiti6-boot2 with Apache License 2.0 | 5 votes |
public static void assertEmailSend(WiserMessage emailMessage, boolean htmlMail, String subject, String message, String from, List<String> to, List<String> cc) throws IOException { try { MimeMessage mimeMessage = emailMessage.getMimeMessage(); if (htmlMail) { assertTrue(mimeMessage.getContentType().contains("multipart/mixed")); } else { assertTrue(mimeMessage.getContentType().contains("text/plain")); } assertEquals(subject, mimeMessage.getHeader("Subject", null)); assertEquals(from, mimeMessage.getHeader("From", null)); assertTrue(getMessage(mimeMessage).contains(message)); for (String t : to) { assertTrue(mimeMessage.getHeader("To", null).contains(t)); } if (cc != null) { for (String c : cc) { assertTrue(mimeMessage.getHeader("Cc", null).contains(c)); } } } catch (MessagingException e) { fail(e.getMessage()); } }
Example 12
Source File: MailerImplTest.java From quarkus with Apache License 2.0 | 5 votes |
@Test void testAttachmentAsStreamLegacy() throws MessagingException, IOException { String payload = UUID.randomUUID().toString(); byte[] bytes = payload.getBytes(StandardCharsets.UTF_8); Iterable<Byte> iterable = () -> new Iterator<Byte>() { private int index = 0; @Override public boolean hasNext() { return bytes.length > index; } @Override public Byte next() { return bytes[index++]; } }; legacyMailer.send(Mail.withText(TO, "Test", "testAttachmentAsStream") .addAttachment("my-file.txt", Flowable.fromIterable(iterable), TEXT_CONTENT_TYPE)) .toCompletableFuture().join(); assertThat(wiser.getMessages()).hasSize(1); WiserMessage actual = wiser.getMessages().get(0); assertThat(getContent(actual)).contains("testAttachment"); MimeMessage msg = actual.getMimeMessage(); assertThat(msg.getSubject()).isEqualTo("Test"); assertThat(msg.getFrom()[0].toString()).isEqualTo(FROM); String value = getAttachment("my-file.txt", (MimeMultipart) actual.getMimeMessage().getContent()); assertThat(value).isEqualTo(payload); }
Example 13
Source File: MailerImplTest.java From quarkus with Apache License 2.0 | 5 votes |
@Test void testAttachmentAsStream() throws MessagingException, IOException { String payload = UUID.randomUUID().toString(); byte[] bytes = payload.getBytes(StandardCharsets.UTF_8); Iterable<Byte> iterable = () -> new Iterator<Byte>() { private int index = 0; @Override public boolean hasNext() { return bytes.length > index; } @Override public Byte next() { return bytes[index++]; } }; mailer.send(Mail.withText(TO, "Test", "testAttachmentAsStream") .addAttachment("my-file.txt", Flowable.fromIterable(iterable), TEXT_CONTENT_TYPE)) .await().indefinitely(); assertThat(wiser.getMessages()).hasSize(1); WiserMessage actual = wiser.getMessages().get(0); assertThat(getContent(actual)).contains("testAttachment"); MimeMessage msg = actual.getMimeMessage(); assertThat(msg.getSubject()).isEqualTo("Test"); assertThat(msg.getFrom()[0].toString()).isEqualTo(FROM); String value = getAttachment("my-file.txt", (MimeMultipart) actual.getMimeMessage().getContent()); assertThat(value).isEqualTo(payload); }
Example 14
Source File: MailerImplTest.java From quarkus with Apache License 2.0 | 5 votes |
@Test void testAttachmentLegacy() throws MessagingException, IOException { String payload = UUID.randomUUID().toString(); legacyMailer.send(Mail.withText(TO, "Test", "testAttachment") .addAttachment("my-file.txt", payload.getBytes(StandardCharsets.UTF_8), TEXT_CONTENT_TYPE)) .toCompletableFuture().join(); assertThat(wiser.getMessages()).hasSize(1); WiserMessage actual = wiser.getMessages().get(0); assertThat(getContent(actual)).contains("testAttachment"); MimeMessage msg = actual.getMimeMessage(); assertThat(msg.getSubject()).isEqualTo("Test"); assertThat(msg.getFrom()[0].toString()).isEqualTo(FROM); String value = getAttachment("my-file.txt", (MimeMultipart) actual.getMimeMessage().getContent()); assertThat(value).isEqualTo(payload); }
Example 15
Source File: MailerImplTest.java From quarkus with Apache License 2.0 | 5 votes |
@Test void testAttachment() throws MessagingException, IOException { String payload = UUID.randomUUID().toString(); mailer.send(Mail.withText(TO, "Test", "testAttachment") .addAttachment("my-file.txt", payload.getBytes(StandardCharsets.UTF_8), TEXT_CONTENT_TYPE)) .await().indefinitely(); assertThat(wiser.getMessages()).hasSize(1); WiserMessage actual = wiser.getMessages().get(0); assertThat(getContent(actual)).contains("testAttachment"); MimeMessage msg = actual.getMimeMessage(); assertThat(msg.getSubject()).isEqualTo("Test"); assertThat(msg.getFrom()[0].toString()).isEqualTo(FROM); String value = getAttachment("my-file.txt", (MimeMultipart) actual.getMimeMessage().getContent()); assertThat(value).isEqualTo(payload); }
Example 16
Source File: MailerImplTest.java From quarkus with Apache License 2.0 | 5 votes |
@Test void testHeadersLegacy() throws MessagingException { legacyMailer.send(Mail.withText(TO, "Test", "testHeaders") .addHeader("X-header", "value") .addHeader("X-header-2", "value1", "value2")) .toCompletableFuture().join(); assertThat(wiser.getMessages()).hasSize(1); WiserMessage actual = wiser.getMessages().get(0); MimeMessage msg = actual.getMimeMessage(); assertThat(msg.getSubject()).isEqualTo("Test"); assertThat(msg.getFrom()[0].toString()).isEqualTo(FROM); assertThat(msg.getHeader("X-header")).hasSize(1).contains("value"); assertThat(msg.getHeader("X-header-2")).hasSize(2).contains("value1", "value2"); }
Example 17
Source File: MailerImplTest.java From quarkus with Apache License 2.0 | 5 votes |
@Test void testHeaders() throws MessagingException { mailer.send(Mail.withText(TO, "Test", "testHeaders") .addHeader("X-header", "value") .addHeader("X-header-2", "value1", "value2")) .await().indefinitely(); assertThat(wiser.getMessages()).hasSize(1); WiserMessage actual = wiser.getMessages().get(0); MimeMessage msg = actual.getMimeMessage(); assertThat(msg.getSubject()).isEqualTo("Test"); assertThat(msg.getFrom()[0].toString()).isEqualTo(FROM); assertThat(msg.getHeader("X-header")).hasSize(1).contains("value"); assertThat(msg.getHeader("X-header-2")).hasSize(2).contains("value1", "value2"); }
Example 18
Source File: MailerImplTest.java From quarkus with Apache License 2.0 | 5 votes |
@Test void testHTMLMailLegacy() throws MessagingException, IOException { String content = UUID.randomUUID().toString(); legacyMailer.send(Mail.withHtml(TO, "Test", "<h1>" + content + "</h1>")).toCompletableFuture().join(); assertThat(wiser.getMessages()).hasSize(1); WiserMessage actual = wiser.getMessages().get(0); assertThat(getContent(actual)).contains("<h1>" + content + "</h1>"); List<String> types = getContentTypesFromMimeMultipart((MimeMultipart) actual.getMimeMessage().getContent()); assertThat(types).containsExactly("text/html"); MimeMessage msg = actual.getMimeMessage(); assertThat(msg.getSubject()).isEqualTo("Test"); assertThat(msg.getContentType()).startsWith("multipart/"); assertThat(msg.getFrom()[0].toString()).isEqualTo(FROM); assertThat(msg.getAllRecipients()).hasSize(1).contains(new InternetAddress(TO)); }
Example 19
Source File: MailerImplTest.java From quarkus with Apache License 2.0 | 5 votes |
@Test void testHTMLMail() throws MessagingException, IOException { String content = UUID.randomUUID().toString(); mailer.send(Mail.withHtml(TO, "Test", "<h1>" + content + "</h1>")).await().indefinitely(); assertThat(wiser.getMessages()).hasSize(1); WiserMessage actual = wiser.getMessages().get(0); assertThat(getContent(actual)).contains("<h1>" + content + "</h1>"); List<String> types = getContentTypesFromMimeMultipart((MimeMultipart) actual.getMimeMessage().getContent()); assertThat(types).containsExactly("text/html"); MimeMessage msg = actual.getMimeMessage(); assertThat(msg.getSubject()).isEqualTo("Test"); assertThat(msg.getContentType()).startsWith("multipart/"); assertThat(msg.getFrom()[0].toString()).isEqualTo(FROM); assertThat(msg.getAllRecipients()).hasSize(1).contains(new InternetAddress(TO)); }
Example 20
Source File: EmailSendTaskTest.java From activiti6-boot2 with Apache License 2.0 | 5 votes |
@Deployment public void testSendEmail() throws Exception { String from = "[email protected]"; boolean male = true; String recipientName = "John Doe"; String recipient = "[email protected]"; Date now = new Date(); String orderId = "123456"; Map<String, Object> vars = new HashMap<String, Object>(); vars.put("sender", from); vars.put("recipient", recipient); vars.put("recipientName", recipientName); vars.put("male", male); vars.put("now", now); vars.put("orderId", orderId); runtimeService.startProcessInstanceByKey("sendMailExample", vars); List<WiserMessage> messages = wiser.getMessages(); assertEquals(1, messages.size()); WiserMessage message = messages.get(0); MimeMessage mimeMessage = message.getMimeMessage(); assertEquals("Your order " + orderId + " has been shipped", mimeMessage.getHeader("Subject", null)); assertEquals(from, mimeMessage.getHeader("From", null)); assertTrue(mimeMessage.getHeader("To", null).contains(recipient)); }