@Test void testWriteSimpleEmail() { final Email email = Email.create().from("Joe@example.com").to("Pig@example.com").textMessage(HELLO); final String eml = EMLComposer.create().compose(email); assertTrue(eml.contains("From: Joe@example.com\r\n")); assertTrue(eml.contains("To: Pig@example.com\r\n")); assertTrue(eml.contains(HELLO)); }
@Test void testSimpleText() throws MessagingException, IOException { final Email email = Email.create() .from(FROM_EXAMPLE_COM) .to(TO_EXAMPLE_COM) .subject(SUB) .textMessage(HELLO); final Message message = createMessage(email); final String content = (String) message.getContent(); assertEquals(HELLO, content); assertTrue(message.getDataHandler().getContentType().contains("text/plain")); }
@Test void testSimpleTextWithCyrilic() throws MessagingException, IOException { final Email email = Email.create() .from("Тијана Милановић <t@gmail.com>") .to("Јодд <i@jodd.com>") .subject("Здраво!") .textMessage("шта радиш?"); final Message message = createMessage(email); final String content = (String) message.getContent(); assertEquals("шта радиш?", content); assertTrue(message.getDataHandler().getContentType().contains("text/plain")); assertEquals("=?UTF-8?B?0KLQuNGY0LDQvdCwINCc0LjQu9Cw0L3QvtCy0LjRmw==?= <t@gmail.com>", message.getFrom()[0].toString()); assertEquals("=?UTF-8?B?0IjQvtC00LQ=?= <i@jodd.com>", message.getRecipients(RecipientType.TO)[0].toString()); }
@Test void testTextHtmlEmbedAttach1() throws MessagingException, IOException { final Email email = Email.create() .from(FROM_EXAMPLE_COM) .to(TO_EXAMPLE_COM) .subject(SUB) .textMessage(HELLO) .htmlMessage("<html><body><h1>Hey!</h1><img src='cid:c.png'></body></html>") .embeddedAttachment(EmailAttachment.with().name(C_PNG).content(BYTES_1_7)) .attachment(EmailAttachment.with().name(FILE_ZIP).content(BYTES_11_15)); assertEmail(email); }
@Test void testSendEmailWithVariousAttachaments() { final SmtpServer smtpServer = MailServer.create() .host(HOST) .auth(USERNAME, PASSWORD) .ssl(true) .buildSmtpMailServer(); final SendMailSession session = smtpServer.createSession(); session.open(); final Email email = Email.create() .from("info@jodd.org") .to("igor.spasic@gmail.com") .subject("test-gmail") .textMessage("Hello!") .htmlMessage( "<html><META http-equiv=Content-Type content=\"text/html; charset=utf-8\">" + "<body><h1>Hey!</h1><img src='cid:jodd.png'>" + "<h2>Hay!</h2><img src='cid:jodd2.png'>" + "<h3></h3></body></html>") .embeddedAttachment(EmailAttachment.with().content(new File(PNG)).inline(false)) .embeddedAttachment(EmailAttachment.with().content(new File(PNG)).contentId("jodd2.png").inline(true)) .attachment(EmailAttachment.with().content(PNG)); session.sendMail(email); session.close(); } }
@Test void testTextHtml() throws MessagingException, IOException { final Email email = Email.create() .from(FROM_EXAMPLE_COM) .to(TO_EXAMPLE_COM) .subject(SUB) .textMessage(HELLO) .htmlMessage("<html><body><h1>Hey!</h1></body></html>"); final Message message = createMessage(email); assertEquals(1, message.getFrom().length); assertEquals(FROM_EXAMPLE_COM, message.getFrom()[0].toString()); assertEquals(1, message.getRecipients(RecipientType.TO).length); assertEquals(TO_EXAMPLE_COM, message.getRecipients(RecipientType.TO)[0].toString()); assertEquals(SUB, message.getSubject()); // wrapper final MimeMultipart multipart = (MimeMultipart) message.getContent(); assertEquals(1, multipart.getCount()); assertTrue(multipart.getContentType().contains("multipart/mixed")); // inner content final MimeBodyPart mimeBodyPart = (MimeBodyPart) multipart.getBodyPart(0); final MimeMultipart mimeMultipart = (MimeMultipart) mimeBodyPart.getContent(); assertEquals(2, mimeMultipart.getCount()); assertTrue(mimeMultipart.getContentType().contains("multipart/alternative")); MimeBodyPart bodyPart = (MimeBodyPart) mimeMultipart.getBodyPart(0); assertEquals(HELLO, bodyPart.getContent()); assertTrue(bodyPart.getDataHandler().getContentType().contains(MimeTypes.MIME_TEXT_PLAIN)); bodyPart = (MimeBodyPart) mimeMultipart.getBodyPart(1); assertEquals("<html><body><h1>Hey!</h1></body></html>", bodyPart.getContent()); assertTrue(bodyPart.getDataHandler().getContentType().contains(MimeTypes.MIME_TEXT_HTML)); }
@Test void testHtmlAndOneAttachment() throws MessagingException, IOException { Email email = Email.create() .from("inf0@jodd.org") .to("ig0r@gmail.com") .subject("test6") .textMessage("Hello!") .attachment(EmailAttachment.with().content(BYTES_11_15, APPLICATION_ZIP)); Message message = createMessage(email); // wrapper final MimeMultipart multipart = (MimeMultipart) message.getContent(); assertEquals(2, multipart.getCount()); // inner content #1 MimeBodyPart mimeBodyPart = (MimeBodyPart) multipart.getBodyPart(0); final MimeMultipart mimeMultipart = (MimeMultipart) mimeBodyPart.getContent(); assertEquals(1, mimeMultipart.getCount()); MimeBodyPart bodyPart = (MimeBodyPart) mimeMultipart.getBodyPart(0); assertEquals("Hello!", bodyPart.getContent()); }
.from("Jodd", "jodd@use.me") .to(GREEN_MAIL_COM) .textMessage("Hello Hello " + count) .attachment(EmailAttachment .with()
.from("Jodd", "jodd@use.me") .to(GREEN_MAIL_COM) .textMessage("Hello " + count) .attachment(EmailAttachment.with().content(new byte[]{(byte) count}));
.from("Jodd", "jodd@use.me") .to(GREEN_MAIL_COM) .textMessage("Hello") .htmlMessage("Hi!")