當前位置: 首頁>>代碼示例>>Java>>正文


Java GreenMail.getReceivedMessages方法代碼示例

本文整理匯總了Java中com.icegreen.greenmail.util.GreenMail.getReceivedMessages方法的典型用法代碼示例。如果您正苦於以下問題:Java GreenMail.getReceivedMessages方法的具體用法?Java GreenMail.getReceivedMessages怎麽用?Java GreenMail.getReceivedMessages使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.icegreen.greenmail.util.GreenMail的用法示例。


在下文中一共展示了GreenMail.getReceivedMessages方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testPipelineStoppedWithMail

import com.icegreen.greenmail.util.GreenMail; //導入方法依賴的package包/類
@Test(timeout = 20000)
public void testPipelineStoppedWithMail() throws Exception {
  Runner runner = pipelineManager.getRunner( TestUtil.PIPELINE_WITH_EMAIL, "0");
  runner.start("admin");
  waitForState(runner, PipelineStatus.RUNNING);
  ((AsyncRunner)runner).getRunner().prepareForStop("admin");
  ((AsyncRunner)runner).getRunner().stop("admin");
  waitForState(runner, PipelineStatus.STOPPED);
  //wait for email
  GreenMail mailServer = TestUtil.TestRuntimeModule.getMailServer();
  while(mailServer.getReceivedMessages().length < 1) {
    ThreadUtil.sleep(100);
  }
  String headers = GreenMailUtil.getHeaders(mailServer.getReceivedMessages()[0]);
  Assert.assertTrue(headers.contains("To: foo, bar"));
  Assert.assertTrue(headers.contains("Subject: StreamsSets Data Collector Alert - " +
      TestUtil.PIPELINE_TITLE_WITH_EMAIL + " - STOPPED"));
  Assert.assertTrue(headers.contains("From: [email protected]"));
  Assert.assertNotNull(GreenMailUtil.getBody(mailServer.getReceivedMessages()[0]));

  mailServer.reset();
}
 
開發者ID:streamsets,項目名稱:datacollector,代碼行數:23,代碼來源:TestStandaloneRunner.java

示例2: testPipelineFinishWithMail

import com.icegreen.greenmail.util.GreenMail; //導入方法依賴的package包/類
@Test(timeout = 20000)
public void testPipelineFinishWithMail() throws Exception {
  Runner runner = pipelineManager.getRunner( TestUtil.PIPELINE_WITH_EMAIL, "0");
  runner.start("admin");
  waitForState(runner, PipelineStatus.RUNNING);
  assertNull(runner.getState().getMetrics());
  TestUtil.EMPTY_OFFSET = true;
  waitForState(runner, PipelineStatus.FINISHED);
  assertNotNull(runner.getState().getMetrics());
  //wait for email
  GreenMail mailServer = TestUtil.TestRuntimeModule.getMailServer();
  while(mailServer.getReceivedMessages().length < 1) {
    ThreadUtil.sleep(100);
  }
  String headers = GreenMailUtil.getHeaders(mailServer.getReceivedMessages()[0]);
  Assert.assertTrue(headers.contains("To: foo, bar"));
  Assert.assertTrue(headers.contains("Subject: StreamsSets Data Collector Alert - " +
      TestUtil.PIPELINE_TITLE_WITH_EMAIL + " - FINISHED"));
  Assert.assertTrue(headers.contains("From: [email protected]"));
  Assert.assertNotNull(GreenMailUtil.getBody(mailServer.getReceivedMessages()[0]));

  mailServer.reset();
}
 
開發者ID:streamsets,項目名稱:datacollector,代碼行數:24,代碼來源:TestStandaloneRunner.java

示例3: testThis

import com.icegreen.greenmail.util.GreenMail; //導入方法依賴的package包/類
private void testThis() throws InterruptedException {
    exc = null;
    final GreenMail greenMail = new GreenMail(ServerSetupTest.SMTP);
    greenMail.setUser("[email protected]","[email protected]");
    greenMail.start();
    final Thread sendThread = new Thread() {
        public void run() {
            try {
                sendMail("[email protected]", "[email protected]", "abc", "def", ServerSetupTest.SMTP);
            } catch (final Throwable e) {
                exc = new RuntimeException(e);
            }
        }
    };
    sendThread.start();
    greenMail.waitForIncomingEmail(3000, 1);
    final MimeMessage[] emails = greenMail.getReceivedMessages();
    assertEquals(1, emails.length);
    greenMail.stop();
    sendThread.join(10000);
    if (exc != null) {
        throw exc;
    }
}
 
開發者ID:greenmail-mail-test,項目名稱:greenmail,代碼行數:25,代碼來源:ConcurrentCloseIT.java

示例4: testSendProvisioningSuccessEmailSMTPS

import com.icegreen.greenmail.util.GreenMail; //導入方法依賴的package包/類
@Ignore
@Test
public void testSendProvisioningSuccessEmailSMTPS() throws IOException, MessagingException {
    //To run this test, please download the greenmail.jks from the following link:
    // https://github.com/greenmail-mail-test/greenmail/blob/master/greenmail-core/src/main/resources/greenmail.jks
    // and put into the /cert/trusted directory, and set the mail.transport.protocol variable to smtps.
    greenMail = new GreenMail(ServerSetupTest.SMTPS);
    greenMail.start();
    //GIVEN
    String content = getFileContent("mail/cluster-installer-mail-success").replaceAll("\\n", "");
    String subject = String.format("%s cluster installation", NAME_OF_THE_CLUSTER);
    //WHEN
    emailSenderService.sendProvisioningSuccessEmail("[email protected]", "xxx", "123.123.123.123", NAME_OF_THE_CLUSTER, false);

    //THEN
    greenMail.waitForIncomingEmail(5000, 1);
    Message[] messages = greenMail.getReceivedMessages();

    Assert.assertEquals(1, messages.length);
    Assert.assertEquals(subject, messages[0].getSubject());
    Assert.assertTrue(String.valueOf(messages[0].getContent()).replaceAll("\\n", "").replaceAll("\\r", "").contains(content));
}
 
開發者ID:hortonworks,項目名稱:cloudbreak,代碼行數:23,代碼來源:EmailSenderHostServiceTypeTest.java

示例5: waitForEmailAndExtractUrl

import com.icegreen.greenmail.util.GreenMail; //導入方法依賴的package包/類
public static String waitForEmailAndExtractUrl(GreenMail smtpServer) throws IOException, MessagingException {
	smtpServer.waitForIncomingEmail(1);
	Message[] messages = smtpServer.getReceivedMessages();
	smtpServer.reset();
	assertEquals(1, messages.length);

	return extractUrlFromMail(messages[0]);
}
 
開發者ID:oojorgeoo89,項目名稱:QuizZz,代碼行數:9,代碼來源:MailHelper.java

示例6: sendsEmaiLToSmtpServer

import com.icegreen.greenmail.util.GreenMail; //導入方法依賴的package包/類
/**
 * SendEmail can send an email envelope to the SMTP server.
 * @throws Exception If something goes wrong.
 */
@Test
public void sendsEmaiLToSmtpServer() throws Exception  {
    String bind = "localhost";
    int port = this.port();
    GreenMail server = this.smtpServer(bind, port);
    server.start();

    SendEmail se = new SendEmail(
        new Postman.Default(
            new SMTP(
                new Token("", "")
                    .access(new Protocol.SMTP(bind, port))
            )
        ), 
        new Envelope.MIME()
            .with(new StSender("Charles Michael <[email protected]>"))
            .with(new StRecipient("[email protected]"))
            .with(new StSubject("test subject: test email"))
            .with(new EnPlain("hello, how are you? This is a test email..."))
    );

    try {
        se.perform(Mockito.mock(Command.class), Mockito.mock(Logger.class));
        final MimeMessage[] messages = server.getReceivedMessages();
        assertTrue(messages.length == 1);
        for (final Message msg : messages) {
            assertTrue(msg.getFrom()[0].toString().contains("<[email protected]>"));
            assertTrue(msg.getSubject().contains("test email"));
        }
    } finally {
        server.stop();
    }
}
 
開發者ID:opencharles,項目名稱:charles-rest,代碼行數:38,代碼來源:SendEmailTestCase.java

示例7: sendsEmailFromGivenUser

import com.icegreen.greenmail.util.GreenMail; //導入方法依賴的package包/類
/**
 * SendEmail can send an email when username, password, host and port are specified.
 * @throws Exception If something goes wrong.
 */
@Test
public void sendsEmailFromGivenUser() throws Exception {
    String bind = "localhost";
    int port = this.port();
    GreenMail server = this.smtpServer(bind, port);
    server.start();
    
    System.setProperty("charles.smtp.username","mihai");
    System.setProperty("charles.smtp.password","");
    System.setProperty("charles.smtp.host","localhost");
    System.setProperty("charles.smtp.port", String.valueOf(port));

    SendEmail se = new SendEmail("[email protected]", "hello", "hello, how are you?");

    try {
        se.perform(Mockito.mock(Command.class), Mockito.mock(Logger.class));
        final MimeMessage[] messages = server.getReceivedMessages();
        assertTrue(messages.length == 1);
        for (final Message msg : messages) {
            assertTrue(msg.getFrom()[0].toString().contains("mihai"));
            assertTrue(msg.getSubject().contains("hello"));
        }
    } finally {
        server.stop();
    }
}
 
開發者ID:opencharles,項目名稱:charles-rest,代碼行數:31,代碼來源:SendEmailTestCase.java

示例8: testSend

import com.icegreen.greenmail.util.GreenMail; //導入方法依賴的package包/類
@Test
public void testSend() throws MessagingException, IOException {
    GreenMail greenMail = new GreenMail(ServerSetupTest.SMTP_IMAP);
    try {
        greenMail.start();

        //Use random content to avoid potential residual lingering problems
        final String subject = GreenMailUtil.random();
        final String body = GreenMailUtil.random();

        sendTestMails(subject, body); // Place your sending code here

        //wait for max 5s for 1 email to arrive
        //waitForIncomingEmail() is useful if you're sending stuff asynchronously in a separate thread
        assertTrue(greenMail.waitForIncomingEmail(5000, 2));

        //Retrieve using GreenMail API
        Message[] messages = greenMail.getReceivedMessages();
        assertEquals(2, messages.length);

        // Simple message
        assertEquals(subject, messages[0].getSubject());
        assertEquals(body, GreenMailUtil.getBody(messages[0]).trim());

        //if you send content as a 2 part multipart...
        assertTrue(messages[1].getContent() instanceof MimeMultipart);
        MimeMultipart mp = (MimeMultipart) messages[1].getContent();
        assertEquals(2, mp.getCount());
        assertEquals("body1", GreenMailUtil.getBody(mp.getBodyPart(0)).trim());
        assertEquals("body2", GreenMailUtil.getBody(mp.getBodyPart(1)).trim());
    } finally {
        greenMail.stop();
    }
}
 
開發者ID:greenmail-mail-test,項目名稱:greenmail,代碼行數:35,代碼來源:ExampleSendNoRuleAdvTest.java

示例9: sendsEmailToTheServerThroughSmtps

import com.icegreen.greenmail.util.GreenMail; //導入方法依賴的package包/類
/**
 * SMTPS postman can send an email to the server through SMTPS wire.
 * @throws Exception If fails
 */
@Test
public void sendsEmailToTheServerThroughSmtps() throws Exception {
    final String bind = "localhost";
    final int received = 1;
    final int port = SmtpsTest.port();
    final int timeout = 3000;
    Security.setProperty(
        "ssl.SocketFactory.provider",
        DummySSLSocketFactory.class.getName()
    );
    final ServerSetup setup = new ServerSetup(
        port, bind, ServerSetup.PROTOCOL_SMTPS
    );
    setup.setServerStartupTimeout(timeout);
    final GreenMail server = new GreenMail(setup);
    server.start();
    try {
        new Postman.Default(
            new Smtps(
                new Token("", "")
                    .access(new Protocol.Smtps(bind, port))
            )
        ).send(
            new Envelope.Safe(
                new Envelope.Mime()
                    .with(new StSender("from <[email protected]>"))
                    .with(new StRecipient("to", "[email protected]"))
                    .with(new StSubject("test subject: test me"))
                    .with(new EnPlain("hello"))
            )
        );
        final MimeMessage[] messages = server.getReceivedMessages();
        MatcherAssert.assertThat(
            messages.length, Matchers.is(received)
        );
        for (final Message msg : messages) {
            MatcherAssert.assertThat(
                msg.getFrom()[0].toString(),
                Matchers.containsString("<[email protected]>")
            );
            MatcherAssert.assertThat(
                msg.getSubject(),  Matchers.containsString("test me")
            );
        }
    } finally {
        server.stop();
    }
}
 
開發者ID:jcabi,項目名稱:jcabi-email,代碼行數:53,代碼來源:SmtpsTest.java

示例10: sendsEmailToSmtpServer

import com.icegreen.greenmail.util.GreenMail; //導入方法依賴的package包/類
/**
 * SMTP postman can send email through SMTP wire.
 * @throws Exception If fails
 */
@Test
public void sendsEmailToSmtpServer() throws Exception {
    final String bind = "localhost";
    final int received = 3;
    final int port = SmtpTest.port();
    final int timeout = 3000;
    final ServerSetup setup = new ServerSetup(
        port, bind, ServerSetup.PROTOCOL_SMTP
    );
    setup.setServerStartupTimeout(timeout);
    final GreenMail server = new GreenMail(setup);
    server.start();
    try {
        new Postman.Default(
            new Smtp(
                new Token("", "")
                    .access(new Protocol.Smtp(bind, port))
            )
        ).send(
            new Envelope.Safe(
                new Envelope.Mime()
                    .with(new StSender("from <test-[email protected]>"))
                    .with(new StRecipient("to", "[email protected]"))
                    .with(new StCc(new InternetAddress("cc <[email protected]>")))
                    .with(new StBcc("bcc <[email protected]>"))
                    .with(new StSubject("test subject: test me"))
                    .with(new EnPlain("hello"))
                    .with(new EnHtml("<p>how are you?</p>"))
            )
        );
        final MimeMessage[] messages = server.getReceivedMessages();
        MatcherAssert.assertThat(
            messages.length,
            Matchers.is(received)
        );
        for (final Message msg : messages) {
            MatcherAssert.assertThat(
                msg.getFrom()[0].toString(),
                Matchers.containsString("<[email protected]>")
            );
            MatcherAssert.assertThat(
                msg.getSubject(),
                Matchers.containsString("test me")
            );
        }
    } finally {
        server.stop();
    }
}
 
開發者ID:jcabi,項目名稱:jcabi-email,代碼行數:54,代碼來源:SmtpTest.java


注:本文中的com.icegreen.greenmail.util.GreenMail.getReceivedMessages方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。