Search in sources :

Example 1 with EasyAuthenticationHandlerFactory

use of org.subethamail.smtp.auth.EasyAuthenticationHandlerFactory in project fake-smtp-server by gessnerfl.

the class SmtpServerConfiguratorTest method shouldConfigureAuthenticationWhenAuthenticationIsConfiguredProperly.

@Test
public void shouldConfigureAuthenticationWhenAuthenticationIsConfiguredProperly() {
    final String username = "username";
    final String password = "password";
    final FakeSmtpConfigurationProperties.Authentication authentication = mock(FakeSmtpConfigurationProperties.Authentication.class);
    when(authentication.getUsername()).thenReturn(username);
    when(authentication.getPassword()).thenReturn(password);
    when(fakeSmtpConfigurationProperties.getAuthentication()).thenReturn(authentication);
    final SMTPServer smtpServer = mock(SMTPServer.class);
    sut.configure(smtpServer);
    ArgumentCaptor<AuthenticationHandlerFactory> argumentCaptor = ArgumentCaptor.forClass(AuthenticationHandlerFactory.class);
    verify(smtpServer).setAuthenticationHandlerFactory(argumentCaptor.capture());
    AuthenticationHandlerFactory authenticationHandlerFactory = argumentCaptor.getValue();
    assertNotNull(authenticationHandlerFactory);
    assertThat(authenticationHandlerFactory, instanceOf(EasyAuthenticationHandlerFactory.class));
    EasyAuthenticationHandlerFactory easyAuthenticationHandlerFactory = (EasyAuthenticationHandlerFactory) authenticationHandlerFactory;
    assertSame(basicUsernamePasswordValidator, easyAuthenticationHandlerFactory.getValidator());
}
Also used : EasyAuthenticationHandlerFactory(org.subethamail.smtp.auth.EasyAuthenticationHandlerFactory) SMTPServer(org.subethamail.smtp.server.SMTPServer) FakeSmtpConfigurationProperties(de.gessnerfl.fakesmtp.config.FakeSmtpConfigurationProperties) AuthenticationHandlerFactory(org.subethamail.smtp.AuthenticationHandlerFactory) EasyAuthenticationHandlerFactory(org.subethamail.smtp.auth.EasyAuthenticationHandlerFactory) Test(org.junit.Test)

Example 2 with EasyAuthenticationHandlerFactory

use of org.subethamail.smtp.auth.EasyAuthenticationHandlerFactory in project simple-email by codylerum.

the class FreeMarkerMailMessageTest method testSMTPSessionAuthentication.

@Test
public void testSMTPSessionAuthentication() throws MessagingException, IOException {
    SimpleMailConfig mailConfig = TestMailConfigs.gmailConfig();
    String subject = "HTML+Text Message from Seam Mail - " + java.util.UUID.randomUUID().toString();
    Person person = new Person(toName, toAddress);
    mailConfig.setServerHost("localHost");
    mailConfig.setServerPort(8978);
    Wiser wiser = new Wiser(mailConfig.getServerPort());
    wiser.getServer().setAuthenticationHandlerFactory(new EasyAuthenticationHandlerFactory(new SMTPAuthenticator("test", "test12!")));
    try {
        wiser.start();
        new MailMessageImpl(mailConfig).from(fromAddress).to(person.getEmail()).subject(subject).put("person", person).put("version", "Seam 3").bodyHtmlTextAlt(new FreeMarkerTemplate(Resources.asCharSource(Resources.getResource("template.html.freemarker"), Charsets.UTF_8).read()), new FreeMarkerTemplate(Resources.asCharSource(Resources.getResource("template.text.freemarker"), Charsets.UTF_8).read())).importance(MessagePriority.LOW).deliveryReceipt(fromAddress).readReceipt(fromAddress).addAttachment("template.html.freemarker", "text/html", ContentDisposition.ATTACHMENT, Resources.asByteSource(Resources.getResource("template.html.freemarker")).read()).addAttachment(new URLAttachment("http://design.jboss.org/seam/logo/final/seam_mail_85px.png", "seamLogo.png", ContentDisposition.INLINE)).send();
    } finally {
        stop(wiser);
    }
    Assert.assertTrue("Didn't receive the expected amount of messages. Expected 1 got " + wiser.getMessages().size(), wiser.getMessages().size() == 1);
    MimeMessage mess = wiser.getMessages().get(0).getMimeMessage();
    Assert.assertEquals("Subject has been modified", subject, MimeUtility.unfold(mess.getHeader("Subject", null)));
    EmailMessage convertedMessage = MessageConverter.convert(mess);
    Assert.assertEquals(convertedMessage.getSubject(), subject);
}
Also used : MailMessageImpl(com.outjected.email.impl.MailMessageImpl) EmailMessage(com.outjected.email.api.EmailMessage) SMTPAuthenticator(com.outjected.email.util.SMTPAuthenticator) URLAttachment(com.outjected.email.impl.attachments.URLAttachment) Wiser(org.subethamail.wiser.Wiser) MimeMessage(javax.mail.internet.MimeMessage) SimpleMailConfig(com.outjected.email.impl.SimpleMailConfig) EasyAuthenticationHandlerFactory(org.subethamail.smtp.auth.EasyAuthenticationHandlerFactory) FreeMarkerTemplate(com.outjected.email.impl.templating.freemarker.FreeMarkerTemplate) Test(org.junit.Test)

Example 3 with EasyAuthenticationHandlerFactory

use of org.subethamail.smtp.auth.EasyAuthenticationHandlerFactory in project simple-email by codylerum.

the class VelocityMailMessageTest method testSMTPSessionAuthentication.

@Test
public void testSMTPSessionAuthentication() throws MessagingException, IOException {
    SessionConfig mailConfig = TestMailConfigs.standardConfig();
    Person person = new Person(toName, toAddress);
    String subject = "HTML+Text Message from Seam Mail - " + java.util.UUID.randomUUID().toString();
    Wiser wiser = new Wiser(mailConfig.getServerPort());
    wiser.setHostname(mailConfig.getServerHost());
    wiser.getServer().setAuthenticationHandlerFactory(new EasyAuthenticationHandlerFactory(new SMTPAuthenticator("test", "test12!")));
    try {
        wiser.start();
        new MailMessageImpl(mailConfig).from(fromAddress).to(person.getEmail()).subject(subject).put("version", "Seam 3").bodyHtmlTextAlt(new VelocityTemplate(Resources.asCharSource(Resources.getResource("template.html.velocity"), Charsets.UTF_8).read()), new VelocityTemplate(Resources.asCharSource(Resources.getResource("template.text.velocity"), Charsets.UTF_8).read())).importance(MessagePriority.LOW).deliveryReceipt(fromAddress).readReceipt(fromAddress).addAttachment("template.html.velocity", "text/html", ContentDisposition.ATTACHMENT, Resources.asByteSource(Resources.getResource("template.html.velocity")).read()).addAttachment(new URLAttachment("http://design.jboss.org/seam/logo/final/seam_mail_85px.png", "seamLogo.png", ContentDisposition.INLINE)).send();
    } finally {
        stop(wiser);
    }
    Assert.assertTrue("Didn't receive the expected amount of messages. Expected 1 got " + wiser.getMessages().size(), wiser.getMessages().size() == 1);
    MimeMessage mess = wiser.getMessages().get(0).getMimeMessage();
    Assert.assertEquals("Subject has been modified", subject, MimeUtility.unfold(mess.getHeader("Subject", null)));
    EmailMessage convertedMessage = MessageConverter.convert(mess);
    Assert.assertEquals(convertedMessage.getSubject(), subject);
}
Also used : VelocityTemplate(com.outjected.email.impl.templating.velocity.VelocityTemplate) MailMessageImpl(com.outjected.email.impl.MailMessageImpl) EmailMessage(com.outjected.email.api.EmailMessage) SMTPAuthenticator(com.outjected.email.util.SMTPAuthenticator) URLAttachment(com.outjected.email.impl.attachments.URLAttachment) Wiser(org.subethamail.wiser.Wiser) MimeMessage(javax.mail.internet.MimeMessage) EasyAuthenticationHandlerFactory(org.subethamail.smtp.auth.EasyAuthenticationHandlerFactory) SessionConfig(com.outjected.email.api.SessionConfig) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)3 EasyAuthenticationHandlerFactory (org.subethamail.smtp.auth.EasyAuthenticationHandlerFactory)3 EmailMessage (com.outjected.email.api.EmailMessage)2 MailMessageImpl (com.outjected.email.impl.MailMessageImpl)2 URLAttachment (com.outjected.email.impl.attachments.URLAttachment)2 SMTPAuthenticator (com.outjected.email.util.SMTPAuthenticator)2 MimeMessage (javax.mail.internet.MimeMessage)2 Wiser (org.subethamail.wiser.Wiser)2 SessionConfig (com.outjected.email.api.SessionConfig)1 SimpleMailConfig (com.outjected.email.impl.SimpleMailConfig)1 FreeMarkerTemplate (com.outjected.email.impl.templating.freemarker.FreeMarkerTemplate)1 VelocityTemplate (com.outjected.email.impl.templating.velocity.VelocityTemplate)1 FakeSmtpConfigurationProperties (de.gessnerfl.fakesmtp.config.FakeSmtpConfigurationProperties)1 AuthenticationHandlerFactory (org.subethamail.smtp.AuthenticationHandlerFactory)1 SMTPServer (org.subethamail.smtp.server.SMTPServer)1