@Test public void testSmtpServerReceiveWithSetup() throws Throwable { assertEquals(0, greenMail.getReceivedMessages().length); String subject = GreenMailUtil.random(); String body = GreenMailUtil.random(); GreenMailUtil.sendTextEmailTest("*****@*****.**", "*****@*****.**", subject, body); greenMail.waitForIncomingEmail(1500, 1); MimeMessage[] emails = greenMail.getReceivedMessages(); assertEquals(1, emails.length); assertEquals(subject, emails[0].getSubject()); assertEquals(body, GreenMailUtil.getBody(emails[0]).trim()); }
@Test public void testSmtpServerReceiveMultipart() throws Exception { assertEquals(0, greenMail.getReceivedMessages().length); String subject = GreenMailUtil.random(); String body = GreenMailUtil.random(); GreenMailUtil.sendAttachmentEmail( "*****@*****.**", "*****@*****.**", subject, body, new byte[] {0, 1, 2}, "image/gif", "testimage_filename", "testimage_description", ServerSetupTest.SMTP); greenMail.waitForIncomingEmail(1500, 1); Message[] emails = greenMail.getReceivedMessages(); assertEquals(1, emails.length); assertEquals(subject, emails[0].getSubject()); Object o = emails[0].getContent(); assertTrue(o instanceof MimeMultipart); MimeMultipart mp = (MimeMultipart) o; assertEquals(2, mp.getCount()); BodyPart bp; bp = mp.getBodyPart(0); assertEquals(body, GreenMailUtil.getBody(bp).trim()); bp = mp.getBodyPart(1); assertEquals("AAEC", GreenMailUtil.getBody(bp).trim()); ByteArrayOutputStream bout = new ByteArrayOutputStream(); GreenMailUtil.copyStream(bp.getInputStream(), bout); byte[] gif = bout.toByteArray(); for (int i = 0; i < gif.length; i++) { assertEquals(i, gif[i]); } }