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

The following examples show how to use com.icegreen.greenmail.util.GreenMail#setUser() . 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: 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 2
Source File: TestEmailNotifier.java    From datacollector with Apache License 2.0 6 votes vote down vote up
@Before
public void setUp() throws Exception {
  ServerSetup serverSetup = new ServerSetup(getFreePort(), "localhost", "smtp");
  server = new GreenMail(serverSetup);
  server.setUser("user@x", "user", "password");
  server.start();

  Configuration conf = new Configuration();
  conf.set("mail.smtp.host", "localhost");
  conf.set("mail.smtp.port", Integer.toString(server.getSmtp().getPort()));
  emailSender = new EmailSender(conf);

  runtimeInfo = new StandaloneRuntimeInfo(
      RuntimeInfo.SDC_PRODUCT,
      RuntimeModule.SDC_PROPERTY_PREFIX,
      new MetricRegistry(),
      Arrays.asList(TestEmailNotifier.class.getClassLoader())
  );
}
 
Example 3
Source File: ExampleReceiveNoRuleTest.java    From greenmail with Apache License 2.0 6 votes vote down vote up
@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();
    }
}
 
Example 4
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 5
Source File: GreenMailServer.java    From micro-integrator 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 6
Source File: TestConsumeEmail.java    From localization_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 7
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 8
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 9
Source File: TestEmailSender.java    From datacollector with Apache License 2.0 5 votes vote down vote up
@BeforeClass
public static void setUp() throws Exception {
  ServerSetup serverSetup = new ServerSetup(getFreePort(), "localhost", "smtp");
  server = new GreenMail(serverSetup);
  server.setUser("user@x", "user", "password");
  server.start();
}
 
Example 10
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 11
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 12
Source File: GreenMailUtilTest.java    From greenmail with Apache License 2.0 5 votes vote down vote up
@Test
public void testSetAndGetQuota() throws MessagingException {
    GreenMail greenMail = new GreenMail(ServerSetupTest.SMTP_IMAP);
    try {
        greenMail.start();

        final GreenMailUser user = greenMail.setUser("foo@localhost", "pwd");

        Store store = greenMail.getImap().createStore();
        store.connect("foo@localhost", "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();
    }
}
 
Example 13
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 14
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");
}