@Test
  public void testLargeMessageTextAndAttachment() throws MessagingException, IOException {
    String to = "to@localhost";
    GreenMailUtil.sendAttachmentEmail(
        to,
        "from@localhost",
        "Subject",
        createLargeString(),
        createLargeByteArray(),
        "application/blubb",
        "file",
        "descr",
        greenMail.getSmtp().getServerSetup());
    greenMail.waitForIncomingEmail(5000, 1);

    retrieveAndCheck(new Retriever(greenMail.getPop3()), to);
    retrieveAndCheck(new Retriever(greenMail.getImap()), to);
  }
Ejemplo n.º 2
0
  @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]);
    }
  }