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());
}
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);
}
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);
}
Aggregations