use of com.helger.commons.email.EmailAddress in project peppol-practical by phax.
the class AppInternalErrorHandler method doSetup.
public static void doSetup() {
// Set global internal error handlers
new AppInternalErrorHandler().install();
final NamedSMTPSettings aNamedSettings = PhotonCoreManager.getSMTPSettingsMgr().getSettings(CNamedSMTPSettings.NAMED_SMTP_SETTINGS_DEFAULT_ID);
final ISMTPSettings aSMTPSettings = aNamedSettings == null ? null : aNamedSettings.getSMTPSettings();
InternalErrorSettings.setSMTPSenderAddress(new EmailAddress("peppol@helger.com", "peppol.helger.com application"));
InternalErrorSettings.setSMTPReceiverAddress(new EmailAddress("philip@helger.com", "Philip"));
InternalErrorSettings.setSMTPSettings(aSMTPSettings);
InternalErrorSettings.setFallbackLocale(CPPApp.DEFAULT_LOCALE);
}
use of com.helger.commons.email.EmailAddress in project phoss-directory by phax.
the class PagePublicContact method fillContent.
@Override
protected void fillContent(@Nonnull final WebPageExecutionContext aWPEC) {
final HCNodeList aNodeList = aWPEC.getNodeList();
final Locale aDisplayLocale = aWPEC.getDisplayLocale();
final boolean bShowForm = true;
final FormErrorList aFormErrors = new FormErrorList();
if (aWPEC.hasAction(CPageParam.ACTION_PERFORM)) {
final String sName = StringHelper.trim(aWPEC.params().getAsString(FIELD_NAME));
final String sEmail = StringHelper.trim(aWPEC.params().getAsString(FIELD_EMAIL));
final String sTopic = aWPEC.params().getAsString(FIELD_TOPIC);
final String sText = StringHelper.trim(aWPEC.params().getAsString(FIELD_TEXT));
final String sReCaptcha = StringHelper.trim(aWPEC.params().getAsString("g-recaptcha-response"));
if (StringHelper.hasNoText(sName))
aFormErrors.addFieldError(FIELD_NAME, "Your name must be provided.");
if (StringHelper.hasNoText(sEmail))
aFormErrors.addFieldError(FIELD_EMAIL, "Your email address must be provided.");
else if (!EmailAddressHelper.isValid(sEmail))
aFormErrors.addFieldError(FIELD_EMAIL, "The provided email address is invalid.");
if (StringHelper.hasNoText(sText))
aFormErrors.addFieldError(FIELD_TEXT, "A message text must be provided.");
if (aFormErrors.isEmpty() || StringHelper.hasText(sReCaptcha)) {
if (!CaptchaSessionSingleton.getInstance().isChecked()) {
// Check only if no other errors occurred
if (ReCaptchaServerSideValidator.check("6LfZFS0UAAAAAONDJHyDnuUUvMB_oNmJxz9Utxza", sReCaptcha).isFailure())
aFormErrors.addFieldError(FIELD_CAPTCHA, "Please confirm you are not a robot!");
else
CaptchaSessionSingleton.getInstance().setChecked();
}
}
if (aFormErrors.isEmpty()) {
final EmailData aEmailData = new EmailData(EEmailType.TEXT);
aEmailData.setFrom(CPDPublisher.EMAIL_SENDER);
aEmailData.to().add(new EmailAddress("pd@helger.com"));
aEmailData.replyTo().add(new EmailAddress(sEmail, sName));
aEmailData.setSubject("[" + CPDPublisher.getApplication() + "] Contact Form - " + sName);
final StringBuilder aSB = new StringBuilder();
aSB.append("Contact form from " + CPDPublisher.getApplication() + " was filled out.\n\n");
aSB.append("Name: ").append(sName).append("\n");
aSB.append("Email: ").append(sEmail).append("\n");
aSB.append("Topic: ").append(sTopic).append("\n");
aSB.append("Text:\n").append(sText).append("\n");
aEmailData.setBody(aSB.toString());
ScopedMailAPI.getInstance().queueMail(InternalErrorSettings.getSMTPSettings(), aEmailData);
aWPEC.postRedirectGetInternal(success("Thank you for your message. We will come back to you asap."));
}
}
if (bShowForm) {
aNodeList.addChild(info("Alternatively write an email to pd[at]helger.com - usually using the below form is more effective!"));
aNodeList.addChild(warn("Please don't request any change of data via this contact form - contact your service provider instead. Thank you."));
final BootstrapForm aForm = aNodeList.addAndReturnChild(getUIHandler().createFormSelf(aWPEC));
aForm.addFormGroup(new BootstrapFormGroup().setLabelMandatory("Your name").setCtrl(new HCEdit(new RequestField(FIELD_NAME))).setErrorList(aFormErrors.getListOfField(FIELD_NAME)));
aForm.addFormGroup(new BootstrapFormGroup().setLabelMandatory("Your email address").setCtrl(new HCEdit(new RequestField(FIELD_EMAIL))).setErrorList(aFormErrors.getListOfField(FIELD_EMAIL)));
final HCExtSelect aSelect = new HCExtSelect(new RequestField(FIELD_TOPIC));
aSelect.addOption("SMP integration");
aSelect.addOption("Website");
aSelect.addOption("REST service");
aSelect.addOption("SMP Statement of use");
aSelect.addOption("General question");
aSelect.addOptionPleaseSelect(aDisplayLocale);
aForm.addFormGroup(new BootstrapFormGroup().setLabel("Topic").setCtrl(aSelect).setErrorList(aFormErrors.getListOfField(FIELD_TOPIC)));
aForm.addFormGroup(new BootstrapFormGroup().setLabelMandatory("Your message").setCtrl(new HCTextAreaAutosize(new RequestField(FIELD_TEXT)).setRows(5)).setErrorList(aFormErrors.getListOfField(FIELD_TEXT)));
if (!CaptchaSessionSingleton.getInstance().isChecked()) {
// Add visible Captcha
aForm.addFormGroup(new BootstrapFormGroup().setCtrl(HCReCaptchaV2.create("6LfZFS0UAAAAAJaqpHJdFS_xxY7dqMQjXoBIQWOD", aDisplayLocale)).setErrorList(aFormErrors.getListOfField(FIELD_CAPTCHA)));
}
aForm.addChild(new HCHiddenField(CPageParam.PARAM_ACTION, CPageParam.ACTION_PERFORM));
aForm.addChild(new BootstrapSubmitButton().addChild("Send message").setIcon(EDefaultIcon.YES));
aForm.addChild(new BootstrapButton().addChild("No thanks").setIcon(EDefaultIcon.CANCEL).setOnClick(aWPEC.getLinkToMenuItem(CMenuPublic.MENU_SEARCH_SIMPLE)));
}
}
use of com.helger.commons.email.EmailAddress in project phoss-directory by phax.
the class AppInternalErrorHandler method doSetup.
public static void doSetup() {
// Set global internal error handlers
new AppInternalErrorHandler().install();
final NamedSMTPSettings aNamedSettings = PhotonCoreManager.getSMTPSettingsMgr().getSettings(CNamedSMTPSettings.NAMED_SMTP_SETTINGS_DEFAULT_ID);
final ISMTPSettings aSMTPSettings = aNamedSettings == null ? null : aNamedSettings.getSMTPSettings();
InternalErrorSettings.setSMTPSenderAddress(new EmailAddress("pd@helger.com", CPDPublisher.getApplicationTitle()));
InternalErrorSettings.setSMTPReceiverAddress(new EmailAddress("philip@helger.com", "Philip"));
InternalErrorSettings.setSMTPSettings(aSMTPSettings);
InternalErrorSettings.setFallbackLocale(AppCommonUI.DEFAULT_LOCALE);
}
use of com.helger.commons.email.EmailAddress 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();
}
}
}
use of com.helger.commons.email.EmailAddress in project ph-web by phax.
the class EmailDataTest method testBasic.
@Test
public void testBasic() {
final EmailData aEmailData = new EmailData(EEmailType.TEXT);
final EmailAddress aMA = new EmailAddress("ph@helger.com", "Philip");
aEmailData.setFrom(aMA);
assertEquals(aMA, aEmailData.getFrom());
aEmailData.replyTo().set(aMA);
assertEquals(aMA, aEmailData.replyTo().get(0));
aEmailData.to().set(aMA);
assertEquals(aMA, aEmailData.to().get(0));
aEmailData.cc().set(aMA);
assertEquals(aMA, aEmailData.cc().get(0));
aEmailData.bcc().set(aMA);
assertEquals(aMA, aEmailData.bcc().get(0));
XMLTestHelper.testMicroTypeConversion(aEmailData);
assertEquals(0, aEmailData.attrs().size());
aEmailData.attrs().putIn("test", "foo");
assertEquals(1, aEmailData.attrs().size());
aEmailData.attrs().putIn("test2", "bar");
assertEquals(2, aEmailData.attrs().size());
XMLTestHelper.testMicroTypeConversion(aEmailData);
}
Aggregations