@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 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 testTextHtmlEmbedAttach2() throws MessagingException, IOException { final Email email = new Email(); email.from(FROM_EXAMPLE_COM); email.to(TO_EXAMPLE_COM); email.subject(SUB); final EmailMessage testMessage = new EmailMessage(HELLO, MimeTypes.MIME_TEXT_PLAIN); email.message(testMessage); final EmailMessage htmlMessage = new EmailMessage( "<html><body><h1>Hey!</h1><img src='cid:c.png'></body></html>", MimeTypes.MIME_TEXT_HTML); email.message(htmlMessage); final EmailAttachment<ByteArrayDataSource> embeddedAttachment = EmailAttachment.with() .content(BYTES_1_7, IMAGE_PNG) .name(C_PNG) .contentId(C_PNG) .inline(true) .buildByteArrayDataSource(); embeddedAttachment.setEmbeddedMessage(htmlMessage); email.embeddedAttachment(embeddedAttachment); final EmailAttachmentBuilder attachmentBuilder = EmailAttachment.with() .content(BYTES_11_15, APPLICATION_ZIP) .name(FILE_ZIP) .contentId(FILE_ZIP); email.attachment(attachmentBuilder); assertEmail(email); }
.contentId(CID_1)) .embeddedAttachment(EmailAttachment.with() .content(BYTES_0_1_0) .inline(true)) .embeddedAttachment(EmailAttachment.with() .content(BYTES_10_11_12) .name(THREE)