Search in sources :

Example 1 with SimpleMessageListenerAdapter

use of org.subethamail.smtp.helper.SimpleMessageListenerAdapter in project vertx-examples by vert-x3.

the class LocalSmtpServer method startWithAuth.

public static void startWithAuth(int port) {
    SMTPServer server = new SMTPServer(new SimpleMessageListenerAdapter(new MyMessageListener()));
    server.setPort(port);
    UsernamePasswordValidator validator = (s, s1) -> {
        if (!"username".equalsIgnoreCase(s) || !"password".equalsIgnoreCase(s1)) {
            throw new LoginFailedException();
        }
    };
    server.setAuthenticationHandlerFactory(new PlainAuthenticationHandlerFactory(validator));
    server.start();
}
Also used : PlainAuthenticationHandlerFactory(org.subethamail.smtp.auth.PlainAuthenticationHandlerFactory) UsernamePasswordValidator(org.subethamail.smtp.auth.UsernamePasswordValidator) LoginFailedException(org.subethamail.smtp.auth.LoginFailedException) SMTPServer(org.subethamail.smtp.server.SMTPServer) SimpleMessageListenerAdapter(org.subethamail.smtp.helper.SimpleMessageListenerAdapter) UsernamePasswordValidator(org.subethamail.smtp.auth.UsernamePasswordValidator) PlainAuthenticationHandlerFactory(org.subethamail.smtp.auth.PlainAuthenticationHandlerFactory) LoginFailedException(org.subethamail.smtp.auth.LoginFailedException) SMTPServer(org.subethamail.smtp.server.SMTPServer) SimpleMessageListenerAdapter(org.subethamail.smtp.helper.SimpleMessageListenerAdapter)

Example 2 with SimpleMessageListenerAdapter

use of org.subethamail.smtp.helper.SimpleMessageListenerAdapter in project fake-smtp-server by gessnerfl.

the class SmtpServerFactoryImpl method create.

@Override
public SmtpServer create() {
    SimpleMessageListenerAdapter simpleMessageListenerAdapter = new SimpleMessageListenerAdapter(emailPersister);
    SMTPServer smtpServer = new SMTPServer(simpleMessageListenerAdapter);
    configurator.configure(smtpServer);
    return new SmtpServerImpl(smtpServer);
}
Also used : SimpleMessageListenerAdapter(org.subethamail.smtp.helper.SimpleMessageListenerAdapter) SMTPServer(org.subethamail.smtp.server.SMTPServer)

Example 3 with SimpleMessageListenerAdapter

use of org.subethamail.smtp.helper.SimpleMessageListenerAdapter in project motech by motech.

the class EmailChannelBundleIT method testEmailSentOnSendEmailEvent.

@Test
public void testEmailSentOnSendEmailEvent() throws MessagingException, IOException, InterruptedException {
    SMTPServer smtpServer = new SMTPServer(new SimpleMessageListenerAdapter(this));
    new Wait(new ContextPublishedWaitCondition(bundleContext, "org.motechproject.motech-platform-event"), 5000).start();
    new Wait(new ContextPublishedWaitCondition(bundleContext), 5000).start();
    try {
        smtpServer.setPort(8099);
        smtpServer.start();
        String messageText = "test message";
        String from = "testfromaddress";
        String to = "testtoaddress";
        String subject = "test subject";
        Map<String, Object> values = new HashMap<>();
        values.put("fromAddress", from);
        values.put("toAddress", to);
        values.put("message", messageText);
        values.put("subject", subject);
        eventRelay.sendEventMessage(new MotechEvent(SendEmailConstants.SEND_EMAIL_SUBJECT, values));
        new Wait(lock, this, 100, 60000).start();
        assertTrue("Message not received", messageReceived);
        assertNotNull(receivedMessageText);
        assertEquals(messageText, receivedMessageText.trim());
    } finally {
        smtpServer.stop();
    }
}
Also used : ContextPublishedWaitCondition(org.motechproject.testing.osgi.wait.ContextPublishedWaitCondition) HashMap(java.util.HashMap) SMTPServer(org.subethamail.smtp.server.SMTPServer) SimpleMessageListenerAdapter(org.subethamail.smtp.helper.SimpleMessageListenerAdapter) Wait(org.motechproject.testing.osgi.wait.Wait) MotechEvent(org.motechproject.event.MotechEvent) Test(org.junit.Test)

Example 4 with SimpleMessageListenerAdapter

use of org.subethamail.smtp.helper.SimpleMessageListenerAdapter in project vertx-examples by vert-x3.

the class LocalSmtpServer method start.

public static void start(int port) {
    SMTPServer smtpServer = new SMTPServer(new SimpleMessageListenerAdapter(new MyMessageListener()));
    smtpServer.setPort(port);
    smtpServer.start();
}
Also used : SMTPServer(org.subethamail.smtp.server.SMTPServer) SimpleMessageListenerAdapter(org.subethamail.smtp.helper.SimpleMessageListenerAdapter)

Aggregations

SimpleMessageListenerAdapter (org.subethamail.smtp.helper.SimpleMessageListenerAdapter)4 SMTPServer (org.subethamail.smtp.server.SMTPServer)4 HashMap (java.util.HashMap)1 Test (org.junit.Test)1 MotechEvent (org.motechproject.event.MotechEvent)1 ContextPublishedWaitCondition (org.motechproject.testing.osgi.wait.ContextPublishedWaitCondition)1 Wait (org.motechproject.testing.osgi.wait.Wait)1 LoginFailedException (org.subethamail.smtp.auth.LoginFailedException)1 PlainAuthenticationHandlerFactory (org.subethamail.smtp.auth.PlainAuthenticationHandlerFactory)1 UsernamePasswordValidator (org.subethamail.smtp.auth.UsernamePasswordValidator)1