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


Java GreenMail.stop方法代碼示例

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


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

示例1: testReceive

import com.icegreen.greenmail.util.GreenMail; //導入方法依賴的package包/類
@Test
public void testReceive() throws MessagingException, IOException {
    //Start all email servers using non-default ports.
    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();
        MimeMessage message = createMimeMessage(subject, body, greenMail); // Construct message
        GreenMailUser user = greenMail.setUser("[email protected]", "waelc", "soooosecret");
        user.deliver(message);
        assertEquals(1, greenMail.getReceivedMessages().length);

        // --- Place your retrieve code here

    } finally {
        greenMail.stop();
    }
}
 
開發者ID:greenmail-mail-test,項目名稱:greenmail,代碼行數:22,代碼來源:ExampleReceiveNoRuleTest.java

示例2: testStartStop

import com.icegreen.greenmail.util.GreenMail; //導入方法依賴的package包/類
@Test
public void testStartStop() {
    GreenMail service = new GreenMail(ServerSetupTest.ALL);
    try {
        // Try to stop before start: Nothing happens
        service.stop();
        service.start();
        service.stop();
        // Now the server is stopped, should be started by reset command
        service.reset();
        // Start again
        service.reset();
    } finally {
        // And finally stop
        service.stop();
    }
}
 
開發者ID:greenmail-mail-test,項目名稱:greenmail,代碼行數:18,代碼來源:ServerStartStopTest.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: 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

示例5: 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

示例6: 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

示例7: testSend

import com.icegreen.greenmail.util.GreenMail; //導入方法依賴的package包/類
@Test
public void testSend() throws MessagingException {
    GreenMail greenMail = new GreenMail(ServerSetupTest.SMTP_IMAP); //uses test ports by default
    try {
        greenMail.start();
        GreenMailUtil.sendTextEmailTest("[email protected]", "[email protected]", "some subject",
                "some body"); //replace this with your test message content
        assertEquals("some body", GreenMailUtil.getBody(greenMail.getReceivedMessages()[0]));
    } finally {
        greenMail.stop();
    }
}
 
開發者ID:greenmail-mail-test,項目名稱:greenmail,代碼行數:13,代碼來源:ExampleSendNoRuleSimpleTest.java

示例8: testUsersAccessible

import com.icegreen.greenmail.util.GreenMail; //導入方法依賴的package包/類
@Test
public void testUsersAccessible() {
    GreenMail greenMail = new GreenMail(ServerSetupTest.IMAP).withConfiguration(
            testUsersAccessibleConfig()
    );
    greenMail.start();
    try {
        GreenMailConfigurationTestBase.testUsersAccessible(greenMail);
    } finally {
        greenMail.stop();
    }
}
 
開發者ID:greenmail-mail-test,項目名稱:greenmail,代碼行數:13,代碼來源:GreenMailConfigurationTest.java

示例9: testSendTextEmailTest

import com.icegreen.greenmail.util.GreenMail; //導入方法依賴的package包/類
@Test
public void testSendTextEmailTest() throws Exception {
    GreenMail greenMail = new GreenMail(ServerSetupTest.SMTP_IMAP);
    try {
        greenMail.setUser("[email protected]", "pwd");
        greenMail.start();
        GreenMailUtil.sendTextEmail("\"Foo, Bar\" <[email protected]>", "\"Bar, Foo\" <[email protected]>",
                "Test subject", "Test message", ServerSetupTest.SMTP);
        greenMail.waitForIncomingEmail(1);

        Store store = greenMail.getImap().createStore();
        store.connect("[email protected]", "pwd");
        try {
            Folder folder = store.getFolder("INBOX");
            folder.open(Folder.READ_ONLY);
            Message[] msgs = folder.getMessages();
            assertTrue(null != msgs && msgs.length == 1);
            Message m = msgs[0];
            assertEquals("Test subject", m.getSubject());
            Address a[] = m.getRecipients(Message.RecipientType.TO);
            assertTrue(null != a && a.length == 1
                    && a[0].toString().equals("\"Foo, Bar\" <[email protected]>"));
            a = m.getFrom();
            assertTrue(null != a && a.length == 1
                    && a[0].toString().equals("\"Bar, Foo\" <[email protected]>"));
            assertTrue(m.getContentType().toLowerCase()
                    .startsWith("text/plain"));
            assertEquals("Test message", m.getContent());
        } finally {
            store.close();
        }
    } finally {
        greenMail.stop();
    }
}
 
開發者ID:greenmail-mail-test,項目名稱:greenmail,代碼行數:36,代碼來源:GreenMailUtilTest.java

示例10: testSetAndGetQuota

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

        final GreenMailUser user = greenMail.setUser("[email protected]", "pwd");

        Store store = greenMail.getImap().createStore();
        store.connect("[email protected]", "pwd");

        Quota testQuota = new Quota("INBOX");
        testQuota.setResourceLimit("STORAGE", 1024L * 42L);
        testQuota.setResourceLimit("MESSAGES", 5L);

        assertEquals(0, GreenMailUtil.getQuota(user, testQuota.quotaRoot).length);
        GreenMailUtil.setQuota(user, testQuota);

        final Quota[] quota = GreenMailUtil.getQuota(user, testQuota.quotaRoot);
        assertEquals(1, quota.length);
        assertEquals(2, quota[0].resources.length);

        store.close();
    } finally {
        greenMail.stop();
    }
}
 
開發者ID:greenmail-mail-test,項目名稱:greenmail,代碼行數:28,代碼來源:GreenMailUtilTest.java

示例11: testResetAndChangePassword

import com.icegreen.greenmail.util.GreenMail; //導入方法依賴的package包/類
@Test
public void testResetAndChangePassword() throws Exception {
    GreenMail mailServer = new GreenMail(ServerSetupTest.SMTP);
    mailServer.start();

    Profile profile = profileService.createProfile(DEFAULT_TENANT, AVASQUEZ_USERNAME, AVASQUEZ_PASSWORD1,
                                                   AVASQUEZ_EMAIL1, true, AVASQUEZ_ROLES1, null, VERIFICATION_URL);

    try {
        profile = profileService.resetPassword(profile.getId().toString(), RESET_PASSWORD_URL);

        assertNotNull(profile);

        // Wait a few seconds so that the email can be sent
        Thread.sleep(3000);

        String email = GreenMailUtil.getBody(mailServer.getReceivedMessages()[0]);

        assertNotNull(email);

        Pattern emailPattern = Pattern.compile(VERIFICATION_EMAIL_REGEX, Pattern.DOTALL);
        Matcher emailMatcher = emailPattern.matcher(email);

        assertTrue(emailMatcher.matches());

        String resetTokenId = emailMatcher.group(1);

        Profile profileAfterPswdReset = profileService.changePassword(resetTokenId, AVASQUEZ_PASSWORD2);

        assertNotNull(profileAfterPswdReset);
        assertEquals(profile.getId(), profileAfterPswdReset.getId());
        assertNull(profileAfterPswdReset.getPassword());
    } finally {
        profileService.deleteProfile(profile.getId().toString());

        mailServer.stop();
    }
}
 
開發者ID:craftercms,項目名稱:profile,代碼行數:39,代碼來源:ProfileServiceIT.java

示例12: 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

示例13: 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-fr[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

示例14: testGetEmptyBodyAndHeader

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

        String subject = GreenMailUtil.random();
        String body = ""; // Provokes https://github.com/greenmail-mail-test/greenmail/issues/151
        String to = "[email protected]";
        final byte[] gifAttachment = {0, 1, 2};
        GreenMailUtil.sendAttachmentEmail(to, "[email protected]", subject, body, gifAttachment,
                "image/gif", "testimage_filename", "testimage_description",
                greenMail.getSmtp().getServerSetup());
        greenMail.waitForIncomingEmail(5000, 1);

        try (Retriever retriever = new Retriever(greenMail.getImap())) {
            MimeMultipart mp = (MimeMultipart) retriever.getMessages(to)[0].getContent();
            BodyPart bp;
            bp = mp.getBodyPart(0);
            assertEquals(body, GreenMailUtil.getBody(bp).trim());
            assertEquals(
                    "Content-Type: text/plain; charset=us-ascii\r\n" +
                    "Content-Transfer-Encoding: 7bit",
                    GreenMailUtil.getHeaders(bp).trim());

            bp = mp.getBodyPart(1);
            assertEquals("AAEC", GreenMailUtil.getBody(bp).trim());
            assertEquals(
                    "Content-Type: image/gif; name=testimage_filename\r\n" +
                    "Content-Transfer-Encoding: base64\r\n" +
                    "Content-Disposition: attachment; filename=testimage_filename\r\n" +
                    "Content-Description: testimage_description",
                    GreenMailUtil.getHeaders(bp).trim());

            ByteArrayOutputStream bout = new ByteArrayOutputStream();
            GreenMailUtil.copyStream(bp.getInputStream(), bout);
            assertArrayEquals(gifAttachment, bout.toByteArray());
        }
    } finally {
        greenMail.stop();
    }
}
 
開發者ID:greenmail-mail-test,項目名稱:greenmail,代碼行數:43,代碼來源:GreenMailUtilTest.java

示例15: testCreateAndVerifyProfile

import com.icegreen.greenmail.util.GreenMail; //導入方法依賴的package包/類
@Test
public void testCreateAndVerifyProfile() throws Exception {
    GreenMail mailServer = new GreenMail(ServerSetupTest.SMTP);
    mailServer.start();

    tenantService.verifyNewProfiles(DEFAULT_TENANT, true);

    Profile profile = profileService.createProfile(DEFAULT_TENANT, AVASQUEZ_USERNAME, AVASQUEZ_PASSWORD1,
                                                   AVASQUEZ_EMAIL1, true, AVASQUEZ_ROLES1, null, VERIFICATION_URL);
    try {
        assertNotNull(profile);
        assertNotNull(profile.getId());
        assertEquals(AVASQUEZ_USERNAME, profile.getUsername());
        assertNull(profile.getPassword());
        assertEquals(AVASQUEZ_EMAIL1, profile.getEmail());
        assertFalse(profile.isVerified());
        assertFalse(profile.isEnabled());
        assertNotNull(profile.getCreatedOn());
        assertNotNull(profile.getLastModified());
        assertEquals(DEFAULT_TENANT, profile.getTenant());
        assertEquals(AVASQUEZ_ROLES1, profile.getRoles());
        assertNotNull(profile.getAttributes());
        assertEquals(0, profile.getAttributes().size());

        // Wait a few seconds so that the email can be sent
        Thread.sleep(3000);

        String email = GreenMailUtil.getBody(mailServer.getReceivedMessages()[0]);

        assertNotNull(email);

        Pattern emailPattern = Pattern.compile(VERIFICATION_EMAIL_REGEX, Pattern.DOTALL);
        Matcher emailMatcher = emailPattern.matcher(email);

        assertTrue(emailMatcher.matches());

        String verificationTokenId = emailMatcher.group(1);

        Profile verifiedProfile = profileService.verifyProfile(verificationTokenId);

        assertNotNull(verifiedProfile);
        assertEquals(profile.getId(), verifiedProfile.getId());
        assertTrue(verifiedProfile.isEnabled());
        assertTrue(verifiedProfile.isVerified());
    } finally {
        profileService.deleteProfile(profile.getId().toString());

        tenantService.verifyNewProfiles(DEFAULT_TENANT, false);

        mailServer.stop();
    }
}
 
開發者ID:craftercms,項目名稱:profile,代碼行數:53,代碼來源:ProfileServiceIT.java


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