Java Code Examples for com.icegreen.greenmail.util.GreenMail#start()

The following examples show how to use com.icegreen.greenmail.util.GreenMail#start() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ConcurrentCloseIT.java    From greenmail with Apache License 2.0 6 votes vote down vote up
private void testThis() throws InterruptedException {
    final GreenMail greenMail = new GreenMail(ServerSetupTest.SMTP);
    greenMail.setUser("test@localhost", "test@localhost");
    greenMail.start();
    final SenderThread sendThread = new SenderThread();
    try {
        sendThread.start();
        greenMail.waitForIncomingEmail(3000, 1);
        final MimeMessage[] emails = greenMail.getReceivedMessages();
        assertEquals(1, emails.length);
        sendThread.join(10000);
    } finally {
        greenMail.stop();
    }

    if (sendThread.exc != null) {
        throw sendThread.exc;
    }
}
 
Example 2
Source File: SshdShellAutoConfigurationTest.java    From sshd-shell-spring-boot with Apache License 2.0 6 votes vote down vote up
@Test
public void testHealthInfoCommand() {
    int smtpPort = SocketUtils.findAvailableTcpPort();
    ServerSetup setup = new ServerSetup(smtpPort, null, ServerSetup.PROTOCOL_SMTP);
    setup.setServerStartupTimeout(5000);
    GreenMail mailServer = new GreenMail(setup);
    JavaMailSenderImpl jmsi = (JavaMailSenderImpl) mailSender;
    mailServer.setUser(jmsi.getUsername(), jmsi.getPassword());
    mailServer.start();
    jmsi.setPort(smtpPort);
    sshCallShell((is, os) -> {
        write(os, "health info");
        verifyResponseContains(is, "{\r\n  \"status\" : \"UP\"");
        mailServer.stop();
    });
}
 
Example 3
Source File: EmailNotificationTest.java    From mxisd with GNU Affero General Public License v3.0 6 votes vote down vote up
@Before
public void before() {
    EmailSmtpConfig smtpCfg = new EmailSmtpConfig();
    smtpCfg.setPort(3025);
    smtpCfg.setLogin(user);
    smtpCfg.setPassword(user);

    EmailConfig eCfg = new EmailConfig();
    eCfg.setConnector(EmailSmtpConnector.ID);
    eCfg.getIdentity().setFrom(sender);
    eCfg.getIdentity().setName(senderName);
    eCfg.getConnectors().put(EmailSmtpConnector.ID, GsonUtil.makeObj(smtpCfg));

    MxisdConfig cfg = new MxisdConfig();
    cfg.getMatrix().setDomain(domain);
    cfg.getKey().setPath(":memory:");
    cfg.getStorage().getProvider().getSqlite().setDatabase(":memory:");
    cfg.getThreepid().getMedium().put(ThreePidMedium.Email.getId(), GsonUtil.makeObj(eCfg));

    m = new Mxisd(cfg);
    m.start();

    gm = new GreenMail(ServerSetupTest.SMTP_IMAP);
    gm.start();
}
 
Example 4
Source File: SmtpOutputOperatorTest.java    From attic-apex-malhar with Apache License 2.0 6 votes vote down vote up
@Before
public void setup() throws Exception
{
  node = new SmtpOutputOperator();
  greenMail = new GreenMail(ServerSetupTest.ALL);
  greenMail.start();
  node.setFrom(from);
  node.setContent(content);
  node.setSmtpHost("127.0.0.1");
  node.setSmtpPort(ServerSetupTest.getPortOffset() + ServerSetup.SMTP.getPort());
  node.setSmtpUserName(from);
  node.setSmtpPassword("<password>");
  //node.setUseSsl(true);
  node.setSubject(subject);
  data = new HashMap<String, String>();
  data.put("alertkey", "alertvalue");

}
 
Example 5
Source File: DefaultEmailServiceContextBasedTest.java    From spring-boot-email-tools with Apache License 2.0 6 votes vote down vote up
@Before
public void setUp() throws Exception {
    when(templateService.mergeTemplateIntoString(anyString(), any(Map.class)))
            .thenReturn("<!doctype html>\n" +
                    "<html>\n" +
                    "<body>\n" +
                    "<p>\n" +
                    "    THIS IS A TEST WITH TEMPLATE\n" +
                    "</p>\n" +
                    "</body>\n" +
                    "</html>");

    ServerSetup serverSetup = new ServerSetup(MAIL_PORT, (String) null, "smtp");
    testSmtp = new GreenMail(serverSetup);
    testSmtp.start();

    //don't forget to set the test port!
    ((JavaMailSenderImpl) javaMailSender).setPort(serverSetup.getPort());
    ((JavaMailSenderImpl) javaMailSender).setHost("localhost");
}
 
Example 6
Source File: GreenMailUtilTest.java    From greenmail with Apache License 2.0 5 votes vote down vote up
@Test
public void testSendTextEmailTest() throws Exception {
    GreenMail greenMail = new GreenMail(ServerSetupTest.SMTP_IMAP);
    try {
        greenMail.setUser("foo@localhost", "pwd");
        greenMail.start();
        GreenMailUtil.sendTextEmail("\"Foo, Bar\" <foo@localhost>", "\"Bar, Foo\" <bar@localhost>",
                "Test subject", "Test message", ServerSetupTest.SMTP);
        greenMail.waitForIncomingEmail(1);

        Store store = greenMail.getImap().createStore();
        store.connect("foo@localhost", "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\" <foo@localhost>"));
            a = m.getFrom();
            assertTrue(null != a && a.length == 1
                    && a[0].toString().equals("\"Bar, Foo\" <bar@localhost>"));
            assertTrue(m.getContentType().toLowerCase()
                    .startsWith("text/plain"));
            assertEquals("Test message", m.getContent());
        } finally {
            store.close();
        }
    } finally {
        greenMail.stop();
    }
}
 
Example 7
Source File: MailServiceTest.java    From Mario with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() {
    greenMail = new GreenMail(ServerSetupTest.SMTP);
    greenMail.setUser(MAIL_MESSAGE_TO, "toForTest", "forTest");
    greenMail.start();

}
 
Example 8
Source File: GreenMailConfigurationTest.java    From greenmail with Apache License 2.0 5 votes vote down vote up
@Test
public void testUsersAccessible() {
    GreenMail greenMail = new GreenMail(ServerSetupTest.IMAP).withConfiguration(
            testUsersAccessibleConfig()
    );
    greenMail.start();
    try {
        GreenMailConfigurationTestBase.testUsersAccessible(greenMail);
    } finally {
        greenMail.stop();
    }
}
 
Example 9
Source File: GreenMailBean.java    From greenmail with Apache License 2.0 5 votes vote down vote up
/**
 * Invoked by a BeanFactory after it has set all bean properties supplied (and satisfied
 * BeanFactoryAware and ApplicationContextAware). <p>This method allows the bean instance to
 * perform initialization only possible when all bean properties have been set and to throw an
 * exception in the event of misconfiguration.
 *
 * @throws Exception in the event of misconfiguration (such as failure to set an essential
 *                   property) or if initialization fails.
 */
@Override
public void afterPropertiesSet() throws Exception {
    greenMail = new GreenMail(createServerSetup());
    if (null != users) {
        for (String user : users) {
            int posColon = user.indexOf(':');
            int posAt = user.indexOf('@');
            String login = user.substring(0, posColon);
            String pwd = user.substring(posColon + 1, posAt);
            String domain = user.substring(posAt + 1);
            if (log.isDebugEnabled()) {
                log.debug("Adding user {}:{}@{}" ,login, pwd, domain);
            }
            greenMail.setUser(login + '@' + domain, login, pwd);
        }
    }
    if (autostart) {
        greenMail.start();
        started = true;
    }
}
 
Example 10
Source File: ITestConsumeEmail.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() {
    mockIMAP4Server = new GreenMail(ServerSetupTest.IMAP);
    mockIMAP4Server.start();
    mockPOP3Server = new GreenMail(ServerSetupTest.POP3);
    mockPOP3Server.start();

    imapUser = mockIMAP4Server.setUser("[email protected]", "nifiUserImap", "nifiPassword");
    popUser = mockPOP3Server.setUser("[email protected]", "nifiUserPop", "nifiPassword");
}
 
Example 11
Source File: MailOperatorFactoryTest.java    From digdag with Apache License 2.0 5 votes vote down vote up
@BeforeClass
public static void smtpSetup()
{
    ServerSetup servers[] = {ServerSetupTest.SMTP, ServerSetupTest.POP3};
    greenMail = new GreenMail(servers);
    greenMail.start();
    smtpPort = greenMail.getSmtp().getPort();
}
 
Example 12
Source File: SendEmailTestCase.java    From charles-rest with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * 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();
    }
}
 
Example 13
Source File: MailServer.java    From keycloak with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    ServerSetup setup = new ServerSetup(3025, "localhost", "smtp");

    GreenMail greenMail = new GreenMail(setup);
    greenMail.start();

    System.out.println("Started mail server (localhost:3025)");
    System.out.println();
    
    while (true) {
        int c = greenMail.getReceivedMessages().length;

        if (greenMail.waitForIncomingEmail(Long.MAX_VALUE, c + 1)) {
            MimeMessage message = greenMail.getReceivedMessages()[c++];
            System.out.println("-------------------------------------------------------");
            System.out.println("Received mail to " + message.getRecipients(RecipientType.TO)[0]);
            if (message.getContent() instanceof MimeMultipart) {
                MimeMultipart mimeMultipart = (MimeMultipart) message.getContent();
                for (int i = 0; i < mimeMultipart.getCount(); i++) {
                    System.out.println("----");
                    System.out.println(mimeMultipart.getBodyPart(i).getContentType() + ":");
                    System.out.println();
                    System.out.println(mimeMultipart.getBodyPart(i).getContent());
                }
            } else {
                System.out.println();
                System.out.println(message.getContent());
            }
            System.out.println("-------------------------------------------------------");
        }
    }
}
 
Example 14
Source File: GreenMailServer.java    From product-ei with Apache License 2.0 5 votes vote down vote up
/**
 * Start the server and add the user.
 */
public static void startServer() {
    greenMail = new GreenMail();
    greenMail.start();
    primaryUser = greenMail.setUser(USER_EMAIL, USER_LOGIN, USER_PW);
    log.info("GreenMail Server started and user added!");
}
 
Example 15
Source File: MailServer.java    From bobcat with Apache License 2.0 5 votes vote down vote up
public void start() {
  Security.setProperty("ssl.SocketFactory.provider", DummySSLSocketFactory.class.getName());
  // from javadoc
  // smtp 3025
  // smtps 3465
  // pop3 3110
  // pop3s 3995
  // imap 3143
  // imaps 3993
  server = new GreenMail();
  server.start();
  server.setUser(address, config.getUsername(), config.getPassword());
}
 
Example 16
Source File: LifeCycleTest.java    From QuizZz with MIT License 5 votes vote down vote up
@Before
public void setup() {
	mvc = MockMvcBuilders.webAppContextSetup(context).apply(springSecurity()).build();

	smtpServer = new GreenMail(ServerSetupTest.SMTP);
	smtpServer.start();
}
 
Example 17
Source File: AbstractTest.java    From smtp-connection-pool with Apache License 2.0 4 votes vote down vote up
protected void startServer() {
  greenMail = new GreenMail(ServerSetupTest.SMTP);
  greenMail.start();
}
 
Example 18
Source File: MailerIT.java    From jeeshop with Apache License 2.0 4 votes vote down vote up
@Before
public void setUp() {
    server = new GreenMail(ServerSetupTest.SMTP);
    server.start();
}
 
Example 19
Source File: CommonTest.java    From hawkular-alerts with Apache License 2.0 4 votes vote down vote up
@Before
public void initSmtpServer() {
    server = new GreenMail(new ServerSetup(TEST_SMTP_PORT, TEST_SMTP_HOST, "smtp"));
    server.start();
}
 
Example 20
Source File: EmailServiceTest.java    From c4sg-services with MIT License 4 votes vote down vote up
@Before
public void setUp() {
	mailer = new GreenMail(new ServerSetup(8825, null, "smtp"));
	mailer.start();
}