use of com.helger.smtp.transport.listener.LoggingTransportListener in project ph-web by phax.
the class MailAPITest method testBasic.
@Ignore("to avoid spamming my mailbox")
@Test
public void testBasic() {
/*
* This file might not be present, as it contains the real-life SMTP
* settings. It should reside in src/test/resource and is SVN ignored by
* name
*/
final IReadableResource aRes = new ClassPathResource("smtp-settings.xml");
if (aRes.exists()) {
final boolean bOldIsDebug = GlobalDebug.isDebugMode();
GlobalDebug.setDebugModeDirect(true);
try {
EmailGlobalSettings.enableJavaxMailDebugging(GlobalDebug.isDebugMode());
// Setup debug listeners
EmailGlobalSettings.addConnectionListener(new LoggingConnectionListener());
EmailGlobalSettings.addConnectionListener(new LoggingConnectionListener(EErrorLevel.WARN));
EmailGlobalSettings.addEmailDataTransportListener(new LoggingTransportListener());
EmailGlobalSettings.addEmailDataTransportListener(new LoggingTransportListener(EErrorLevel.WARN));
final SMTPSettings aSMTPSettings = MicroTypeConverter.convertToNative(MicroReader.readMicroXML(aRes).getDocumentElement(), SMTPSettings.class);
final IMutableEmailData aMailData = new EmailData(EEmailType.TEXT);
aMailData.to().add(new EmailAddress("ph@helger.com"));
aMailData.cc().add(new EmailAddress("hudri@helger.com"));
aMailData.setFrom(new EmailAddress("auto@helger.com"));
aMailData.setSubject("JÜnit test with späcial käräktärs");
aMailData.setBody("Hi there\nLine 2\n4 special chars: äöüß\n123456789\nBest regards: ph-smtp");
MailAPI.queueMail(aSMTPSettings, aMailData);
MailAPI.stop();
/*
* try to queue again after MailAPI was stopped - should end up in
* failed mail queue
*/
assertEquals(0, MailAPI.getFailedMailQueue().size());
MailAPI.queueMail(aSMTPSettings, aMailData);
assertEquals(1, MailAPI.getFailedMailQueue().size());
} finally {
GlobalDebug.setDebugModeDirect(bOldIsDebug);
EmailGlobalSettings.setToDefault();
}
}
}
Aggregations