com.icegreen.greenmail.util.ServerSetupTest Java Examples

The following examples show how to use com.icegreen.greenmail.util.ServerSetupTest. 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: AutoRetryTest.java    From ogham with Apache License 2.0 6 votes vote down vote up
@Test
public void doNotResendEmailIfInvalidTemplate() throws MessagingException {
	// @formatter:off
	builder
		.environment()
			.properties()
				.set("mail.smtp.host", ServerSetupTest.SMTP.getBindAddress())
				.set("mail.smtp.port", ServerSetupTest.SMTP.getPort());
	// @formatter:on
	MessagingService messagingService = builder.build();
	// @formatter:off
	MessageNotSentException e = assertThrows("should throw", MessageNotSentException.class, () -> {
		messagingService.send(new Email()
				.from("[email protected]")
				.to("[email protected]")
				.body().template("/template/thymeleaf/source/invalid.html", new SimpleBean("foo", 42)));
	});
	// @formatter:on
	assertThat("should indicate that this is due to unrecoverable error", e, hasAnyCause(UnrecoverableException.class));
	assertThat("should indicate original exceptions", e, executionFailures(UnrecoverableException.class, hasSize(1)));
	assertThat("should indicate original exceptions", e, executionFailures(UnrecoverableException.class, hasItem(hasAnyCause(instanceOf(TemplateParsingFailedException.class)))));
	assertThat("should indicate original exceptions", e, executionFailures(UnrecoverableException.class, hasItem(hasAnyCause(instanceOf(ParseException.class)))));
	assertThat("should indicate original exceptions", e, executionFailures(UnrecoverableException.class, hasItem(hasAnyCause(instanceOf(TemplateProcessingException.class)))));
}
 
Example #2
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 #3
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 #4
Source File: UserManagerTest.java    From greenmail with Apache License 2.0 6 votes vote down vote up
@Test
public void testDeleteUserShouldDeleteMail() throws Exception {
    ImapHostManager imapHostManager = new ImapHostManagerImpl(new InMemoryStore());
    UserManager userManager = new UserManager(imapHostManager);

    GreenMailUser user = userManager.createUser("[email protected]", "foo", "pwd");
    assertEquals(1, userManager.listUser().size());

    imapHostManager.createPrivateMailAccount(user);
    MailFolder otherfolder = imapHostManager.createMailbox(user, "otherfolder");
    MailFolder inbox = imapHostManager.getFolder(user, ImapConstants.INBOX_NAME);

    ServerSetup ss = ServerSetupTest.IMAP;
    MimeMessage m1 = GreenMailUtil.createTextEmail("there@localhost", "here@localhost", "sub1", "msg1", ss);
    MimeMessage m2 = GreenMailUtil.createTextEmail("there@localhost", "here@localhost", "sub1", "msg1", ss);

    inbox.store(m1);
    otherfolder.store(m2);
 
    userManager.deleteUser(user);
    assertTrue(imapHostManager.getAllMessages().isEmpty());
}
 
Example #5
Source File: EMailTestServer.java    From syndesis with Apache License 2.0 6 votes vote down vote up
public EMailTestServer(String hostName, Options... options) {
    this.optionsList = Arrays.asList(options);

    if (optionsList.contains(Options.IMAP)) {
        initServer(hostName, ServerSetupTest.IMAP, () -> greenMail.getImap());
    } else if (optionsList.contains(Options.IMAPS)) {
        initServer(hostName, ServerSetupTest.IMAPS, () -> greenMail.getImaps());
    } else if (optionsList.contains(Options.POP3)) {
        initServer(hostName, ServerSetupTest.POP3, () -> greenMail.getPop3());
    } else if (optionsList.contains(Options.POP3S)) {
        initServer(hostName, ServerSetupTest.POP3S, () -> greenMail.getPop3s());
    } else if (optionsList.contains(Options.SMTP)) {
        initServer(hostName, ServerSetupTest.SMTP, () -> greenMail.getSmtp());
    } else if (optionsList.contains(Options.SMTPS)) {
        initServer(hostName, ServerSetupTest.SMTPS, () -> greenMail.getSmtps());
    } else {
        throw new UnsupportedOperationException("Server must be either IMAP(S), POP3(S) or SMTP(S)");
    }
}
 
Example #6
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 #7
Source File: ServerStartStopTest.java    From greenmail with Apache License 2.0 6 votes vote down vote up
@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();
    }
}
 
Example #8
Source File: EmailSMTPAuthenticationTest.java    From ogham with Apache License 2.0 6 votes vote down vote up
@Before
public void setUp() throws IOException {
	greenMail.setUser("[email protected]", "test.sender", "password");							// <1>
	oghamService = MessagingBuilder.standard()
			.environment()
				.properties("/application.properties")
				.properties()
					.set("mail.smtp.host", ServerSetupTest.SMTP.getBindAddress())
					.set("mail.smtp.port", ServerSetupTest.SMTP.getPort())
					.set("mail.smtp.auth", "true")												// <2>
					.set("ogham.email.javamail.authenticator.username", "test.sender")			// <3>
					.set("ogham.email.javamail.authenticator.password", "password")				// <4>
					.and()
				.and()
			.build();
}
 
Example #9
Source File: EmailDifferentPrefixesTest.java    From ogham with Apache License 2.0 6 votes vote down vote up
@Before
public void setUp() throws IOException {
	// copy files
	File folder = temp.newFolder("template", "mixed", "source");
	File thymeleafFolder = folder.toPath().resolve("thymeleaf").toFile();
	thymeleafFolder.mkdirs();
	File freemarkerFolder = folder.toPath().resolve("freemarker").toFile();
	freemarkerFolder.mkdirs();
	IOUtils.copy(resource("template/thymeleaf/source/simple.html"), thymeleafFolder.toPath().resolve("simple.html").toFile());
	IOUtils.copy(resource("template/freemarker/source/simple.txt.ftl"), freemarkerFolder.toPath().resolve("simple.txt.ftl").toFile());
	// prepare ogham
	oghamService = MessagingBuilder.standard()
			.environment()
				.properties("/application.properties")
				.properties()
					.set("mail.smtp.host", ServerSetupTest.SMTP.getBindAddress())
					.set("mail.smtp.port", String.valueOf(ServerSetupTest.SMTP.getPort()))
					.set("ogham.email.thymeleaf.classpath.path-prefix", "/template/thymeleaf/source/")
					.set("ogham.email.thymeleaf.file.path-prefix", thymeleafFolder.getAbsolutePath()+"/")
					.set("ogham.email.freemarker.classpath.path-prefix", "/template/freemarker/source/")
					.set("ogham.email.freemarker.file.path-prefix", freemarkerFolder.getAbsolutePath()+"/")
					.and()
				.and()
			.build();
}
 
Example #10
Source File: EmailSMTPDefaultsTest.java    From ogham with Apache License 2.0 6 votes vote down vote up
@Before
public void setUp() throws IOException {
	Properties additionalProps = new Properties();
	additionalProps.setProperty("mail.smtp.host", ServerSetupTest.SMTP.getBindAddress());
	additionalProps.setProperty("mail.smtp.port", String.valueOf(ServerSetupTest.SMTP.getPort()));
	oghamService = MessagingBuilder.standard()
			.email()
			.images()
				.inline()
					.attach()
						.cid()
							.generator(new SequentialIdGenerator(true))
							.and().and().and().and().and()
			.environment()
				.properties("/application.properties")
				.properties(additionalProps)
				.and()
			.build();
}
 
Example #11
Source File: EmailPropertiesTest.java    From ogham with Apache License 2.0 6 votes vote down vote up
@Before
public void setUp() throws IOException {
	Properties additional = new Properties();
	additional.setProperty("mail.smtp.host", ServerSetupTest.SMTP.getBindAddress());
	additional.setProperty("mail.smtp.port", String.valueOf(ServerSetupTest.SMTP.getPort()));
	additional.setProperty("ogham.email.from.default-value", "[email protected]");
	additional.setProperty("ogham.email.to.default-value", "[email protected],  [email protected] , [email protected]");   // <1>
	additional.setProperty("ogham.email.cc.default-value", "[email protected],[email protected]");                            // <2>
	additional.setProperty("ogham.email.bcc.default-value", "[email protected]");                                                // <3>
	oghamService = MessagingBuilder.standard()
			.environment()
				.properties("/application.properties")
				.properties(additional)
				.and()
			.build();
}
 
Example #12
Source File: FluentEmailTest.java    From ogham with Apache License 2.0 6 votes vote down vote up
@Before
public void setUp() throws IOException {
	Properties additionalProps = new Properties();
	additionalProps.setProperty("mail.smtp.host", ServerSetupTest.SMTP.getBindAddress());
	additionalProps.setProperty("mail.smtp.port", String.valueOf(ServerSetupTest.SMTP.getPort()));
	oghamService = MessagingBuilder.standard()
			.email()
			.images()
				.inline()
					.attach()
						.cid()
							.generator(new SequentialIdGenerator(true))
							.and().and().and().and().and()
			.environment()
				.properties("/application.properties")
				.properties(additionalProps)
				.and()
			.build();
}
 
Example #13
Source File: AutoRetryTest.java    From ogham with Apache License 2.0 6 votes vote down vote up
@Test
public void doNotResendEmailIfMimetypeDetectionFailed() throws MessagingException {
	// @formatter:off
	builder
		.environment()
			.properties()
				.set("mail.smtp.host", ServerSetupTest.SMTP.getBindAddress())
				.set("mail.smtp.port", ServerSetupTest.SMTP.getPort());
	// @formatter:on
	MessagingService messagingService = builder.build();
	// @formatter:off
	MessageNotSentException e = assertThrows("should throw", MessageNotSentException.class, () -> {
		messagingService.send(new Email()
				.from("[email protected]")
				.to("[email protected]")
				.body().template("/template/freemarker/source/invalid-image-mimetype.html.ftl", new SimpleBean("foo", 42)));
	});
	// @formatter:on
	assertThat("should indicate that this is due to unrecoverable error", e, hasAnyCause(UnrecoverableException.class));
	assertThat("should indicate original exceptions", e, executionFailures(UnrecoverableException.class, hasSize(1)));
	assertThat("should indicate original exceptions", e, executionFailures(UnrecoverableException.class, hasItem(hasAnyCause(instanceOf(ImageInliningException.class)))));
	assertThat("should indicate original exceptions", e, executionFailures(UnrecoverableException.class, hasItem(hasAnyCause(instanceOf(MimeTypeDetectionException.class)))));
}
 
Example #14
Source File: AutoRetryTest.java    From ogham with Apache License 2.0 6 votes vote down vote up
@Test
public void doNotResendEmailIfResourceUnresolved() throws MessagingException {
	// @formatter:off
	builder
		.environment()
			.properties()
				.set("mail.smtp.host", ServerSetupTest.SMTP.getBindAddress())
				.set("mail.smtp.port", ServerSetupTest.SMTP.getPort());
	// @formatter:on
	MessagingService messagingService = builder.build();
	// @formatter:off
	MessageNotSentException e = assertThrows("should throw", MessageNotSentException.class, () -> {
		messagingService.send(new Email()
				.from("[email protected]")
				.to("[email protected]")
				.body().template("/template/freemarker/source/invalid-resources.html.ftl", new SimpleBean("foo", 42)));
	});
	// @formatter:on
	assertThat("should indicate that this is due to unrecoverable error", e, hasAnyCause(UnrecoverableException.class));
	assertThat("should indicate original exceptions", e, executionFailures(UnrecoverableException.class, hasSize(1)));
	assertThat("should indicate original exceptions", e, executionFailures(UnrecoverableException.class, hasItem(hasAnyCause(instanceOf(ImageInliningException.class)))));
	assertThat("should indicate original exceptions", e, executionFailures(UnrecoverableException.class, hasItem(hasAnyCause(instanceOf(ResourceResolutionException.class)))));
}
 
Example #15
Source File: AutoRetryTest.java    From ogham with Apache License 2.0 6 votes vote down vote up
@Test
public void doNotResendEmailIfTemplateNotFound() throws MessagingException {
	// @formatter:off
	builder
		.environment()
			.properties()
				.set("mail.smtp.host", ServerSetupTest.SMTP.getBindAddress())
				.set("mail.smtp.port", ServerSetupTest.SMTP.getPort());
	// @formatter:on
	MessagingService messagingService = builder.build();
	// @formatter:off
	MessageNotSentException e = assertThrows("should throw", MessageNotSentException.class, () -> {
		messagingService.send(new Email()
				.from("[email protected]")
				.to("[email protected]")
				.body().template("/not-found.html.ftl", null));
	});
	// @formatter:on
	assertThat("should indicate that this is due to unrecoverable error", e, hasAnyCause(UnrecoverableException.class));
	assertThat("should indicate original exceptions", e, executionFailures(UnrecoverableException.class, hasSize(1)));
	assertThat("should indicate original exceptions", e, executionFailures(UnrecoverableException.class, hasItem(hasAnyCause(instanceOf(NoContentException.class)))));
	assertThat("should indicate original exceptions", e, missingContentFailures(UnrecoverableException.class, hasItems(instanceOf(TemplateNotFoundException.class), instanceOf(TemplateNotFoundException.class))));
}
 
Example #16
Source File: ThymeleafRelativeResourcesTest.java    From ogham with Apache License 2.0 6 votes vote down vote up
public void setup(Property... specificProps) throws IOException {
	// disable freemarker to be sure to use thymeleaf
	disableFreemarker();
	Properties additionalProps = new Properties();
	additionalProps.setProperty("mail.smtp.host", ServerSetupTest.SMTP.getBindAddress());
	additionalProps.setProperty("mail.smtp.port", String.valueOf(ServerSetupTest.SMTP.getPort()));
	if(specificProps != null) {
		for(Property prop : specificProps) {
			additionalProps.setProperty(prop.getKey(), prop.getValue());
		}
	}
	oghamService = MessagingBuilder.standard()
			.email()
			.images()
				.inline()
					.attach()
						.cid()
							.generator(new SequentialIdGenerator(true))
							.and().and().and().and().and()
			.environment()
				.properties("/application.properties")
				.properties(additionalProps)
				.and()
			.build();
}
 
Example #17
Source File: FreemarkerRelativeResourcesTests.java    From ogham with Apache License 2.0 6 votes vote down vote up
public void setup(Property... specificProps) throws IOException {
	// disable thymeleaf to be sure to use freemarker
	disableThymeleaf();
	Properties additionalProps = new Properties();
	additionalProps.setProperty("mail.smtp.host", ServerSetupTest.SMTP.getBindAddress());
	additionalProps.setProperty("mail.smtp.port", String.valueOf(ServerSetupTest.SMTP.getPort()));
	if(specificProps != null) {
		for(Property prop : specificProps) {
			additionalProps.setProperty(prop.getKey(), prop.getValue());
		}
	}
	oghamService = MessagingBuilder.standard()
			.email()
				.images()
					.inline()
						.attach()
							.cid()
								.generator(new SequentialIdGenerator(true))
								.and().and().and().and().and()
			.environment()
				.properties("/application.properties")
				.properties(additionalProps)
				.and()
			.build();
}
 
Example #18
Source File: StaticMethodsAccessTest.java    From ogham with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() {
	context = new AnnotationConfigApplicationContext();
	EnvironmentTestUtils.addEnvironment(context, 
			"mail.smtp.host="+ServerSetupTest.SMTP.getBindAddress(), 
			"mail.smtp.port="+ServerSetupTest.SMTP.getPort(),
			"ogham.sms.smpp.host=127.0.0.1",
			"ogham.sms.smpp.port="+smppServer.getPort(),
			"spring.freemarker.suffix=");
	context.register( FreeMarkerAutoConfiguration.class, OghamSpringBoot1AutoConfiguration.class);
	context.refresh();
	messagingService = context.getBean(MessagingService.class);
}
 
Example #19
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 #20
Source File: SpringBeanResolutionTest.java    From ogham with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() {
	context = new AnnotationConfigApplicationContext();
	EnvironmentTestUtils.addEnvironment(context, 
			"mail.smtp.host="+ServerSetupTest.SMTP.getBindAddress(), 
			"mail.smtp.port="+ServerSetupTest.SMTP.getPort(),
			"ogham.sms.smpp.host=127.0.0.1",
			"ogham.sms.smpp.port="+smppServer.getPort(),
			"spring.freemarker.suffix=");
	context.register(TestConfig.class, ThymeleafAutoConfiguration.class, FreeMarkerAutoConfiguration.class, OghamSpringBoot1AutoConfiguration.class);
	context.refresh();
	messagingService = context.getBean(MessagingService.class);
}
 
Example #21
Source File: OghamSpringBoot2AutoConfigurationTests.java    From ogham with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() {
	contextRunner = new ApplicationContextRunner()
			.withPropertyValues("mail.smtp.host="+ServerSetupTest.SMTP.getBindAddress(), 
					"mail.smtp.port="+ServerSetupTest.SMTP.getPort(),
					"ogham.sms.smpp.host=127.0.0.1",
					"ogham.sms.smpp.port="+smppServer.getPort(),
					"ogham.email.sendgrid.api-key=ogham",
					"spring.sendgrid.api-key=spring",
					"ogham.freemarker.default-encoding="+StandardCharsets.US_ASCII.name(),
					"spring.freemarker.charset="+StandardCharsets.UTF_16BE.name());
}
 
Example #22
Source File: JavaMailStructureTest.java    From ogham with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() throws IOException {
	sender = new JavaMailBuilder()
			.host(ServerSetupTest.SMTP.getBindAddress())
			.port(ServerSetupTest.SMTP.getPort())
			.mimetype()
				.tika()
					.failIfOctetStream(false)
					.and()
				.and()
			.build();
}
 
Example #23
Source File: JavaMailCustomConfigurationTest.java    From ogham with Apache License 2.0 5 votes vote down vote up
@Test
public void oghamPropertyShouldOverride() throws MessagingException {
	Properties additionalProps = new Properties();
	additionalProps.setProperty("ogham.email.javamail.host", ServerSetupTest.SMTP.getBindAddress());
	additionalProps.setProperty("ogham.email.javamail.port", String.valueOf(ServerSetupTest.SMTP.getPort()));
	additionalProps.setProperty("mail.smtp.host", "value of mail.smtp.host");
	additionalProps.setProperty("mail.smtp.port", "value of mail.smtp.port");
	additionalProps.setProperty("mail.host", "value of mail.host");
	additionalProps.setProperty("mail.port", "value of mail.port");
	MessagingService service = MessagingBuilder.empty()
			.environment()
				.properties(additionalProps)
				.and()
			.email()
				.sender(JavaMailBuilder.class)
				.mimetype()
					.tika()
						.failIfOctetStream(false)
						.and()
					.and()
				.host().properties("${ogham.email.javamail.host}", "${mail.smtp.host}", "${mail.host}").and()
				.port().properties("${ogham.email.javamail.port}", "${mail.smtp.port}", "${mail.port}").and()
				.and()
			.and()
			.build();
	// send the message
	service.send(new Email()
			.from("[email protected]")
			.to("[email protected]")
			.content("test")
			.subject("subject"));
	assertThat(greenMail).receivedMessages().count(is(1));
}
 
Example #24
Source File: UnreadableAttachmentTest.java    From ogham with Apache License 2.0 5 votes vote down vote up
@Before
public void setup() throws IOException {
	MessagingBuilder builder = MessagingBuilder.standard();
	builder
		.environment()
			.properties()
				.set("mail.smtp.host", ServerSetupTest.SMTP.getBindAddress())
				.set("mail.smtp.port", ServerSetupTest.SMTP.getPort());
	service = builder.build();
	unreadable = temp.newFile("UNREADABLE");
	unreadable.setReadable(false);
}
 
Example #25
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 #26
Source File: ExampleSendNoRuleSimpleTest.java    From greenmail with Apache License 2.0 5 votes vote down vote up
@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();
    }
}
 
Example #27
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 #28
Source File: DockerServiceIT.java    From greenmail with Apache License 2.0 5 votes vote down vote up
@Test
public void testAllServices() throws MessagingException, InterruptedException {
    // Ugly workaround : GreenMail in docker starts with open TCP connections,
    //                   but TLS sockets might not be ready yet.
    TimeUnit.SECONDS.sleep(1);

    // Send messages via SMTP and secure SMTPS
    GreenMailUtil.sendTextEmail("foo@localhost", "bar@localhost",
            "test1", "Test GreenMail Docker service",
            ServerSetupTest.SMTP.createCopy(bindAddress));
    GreenMailUtil.sendTextEmail("foo@localhost", "bar@localhost",
            "test2", "Test GreenMail Docker service",
            ServerSetupTest.SMTPS.createCopy(bindAddress));

    // IMAP
    for (ServerSetup setup : Arrays.asList(
            ServerSetupTest.IMAP.createCopy(bindAddress),
            ServerSetupTest.IMAPS.createCopy(bindAddress),
            ServerSetupTest.POP3.createCopy(bindAddress),
            ServerSetupTest.POP3S.createCopy(bindAddress))) {
        final Store store = Session.getInstance(setup.configureJavaMailSessionProperties(null, false)).getStore();
        store.connect("foo@localhost", "foo@localhost");
        try {
            Folder folder = store.getFolder("INBOX");
            folder.open(Folder.READ_ONLY);
            assertEquals("Can not check mails using "+store.getURLName(), 2, folder.getMessageCount());
        } finally {
            store.close();
        }
    }
}
 
Example #29
Source File: ConcurrentCloseIT.java    From greenmail with Apache License 2.0 5 votes vote down vote up
public void run() {
    try {
        GreenMailUtil.sendTextEmail("test@localhost", "from@localhost", "abc", "def", ServerSetupTest.SMTP);
    } catch (final Throwable e) {
        exc = new IllegalStateException(e);
    }
}
 
Example #30
Source File: ExamplePurgeAllEmailsTest.java    From greenmail with Apache License 2.0 5 votes vote down vote up
@Test
public void testremoveAllMessagesInImapMailbox() throws FolderException {
    try (Retriever retriever = new Retriever(greenMailRule.getImap())) {
        greenMailRule.setUser("foo@localhost", "pwd");
        GreenMailUtil.sendTextEmail("foo@localhost", "bar@localhost",
                "Test subject", "Test message", ServerSetupTest.SMTP);
        assertTrue(greenMailRule.waitForIncomingEmail(1));
        greenMailRule.purgeEmailFromAllMailboxes();
        Message[] messages = retriever.getMessages("foo@localhost", "pwd");
        assertEquals(0, messages.length);
    }

}