use of com.serotonin.m2m2.email.MangoEmailContent in project ma-core-public by infiniteautomation.
the class PasswordResetService method sendEmail.
public void sendEmail(User user, String token) throws TemplateException, IOException, AddressException {
URI uri = null;
try {
uri = this.generateResetUrl(token);
} catch (Exception e) {
}
Translations translations = Translations.getTranslations(user.getLocaleObject());
Jws<Claims> parsed = this.parse(token);
Date expiration = parsed.getBody().getExpiration();
Map<String, Object> model = new HashMap<>();
model.put("username", user.getUsername());
model.put("resetUri", uri != null ? uri : "");
model.put("token", token);
model.put("expiration", expiration);
TranslatableMessage subject = new TranslatableMessage("ftl.passwordReset.subject", user.getUsername());
MangoEmailContent content = new MangoEmailContent("passwordReset", model, translations, subject.translate(translations), Common.UTF8);
EmailWorkItem.queueEmail(user.getEmail(), content);
}
use of com.serotonin.m2m2.email.MangoEmailContent in project ma-core-public by infiniteautomation.
the class SystemSettingsDwr method sendTestEmail.
@DwrPermission(admin = true)
public Map<String, Object> sendTestEmail(String host, int port, String from, String name, boolean auth, String username, String password, boolean tls, int contentType) {
// Save the settings
saveEmailSettings(host, port, from, name, auth, username, password, tls, contentType);
// Get the web context information
User user = Common.getHttpUser();
Map<String, Object> result = new HashMap<>();
try {
Translations translations = getTranslations();
Map<String, Object> model = new HashMap<>();
model.put("message", new TranslatableMessage("systemSettings.testEmail"));
MangoEmailContent cnt = new MangoEmailContent("testEmail", model, translations, translations.translate("ftl.testEmail"), Common.UTF8);
EmailWorkItem.queueEmail(user.getEmail(), cnt);
result.put("message", new TranslatableMessage("common.testEmailSent", user.getEmail()));
} catch (Exception e) {
result.put("exception", e.getMessage());
}
return result;
}
use of com.serotonin.m2m2.email.MangoEmailContent in project ma-modules-public by infiniteautomation.
the class ServerRestV2Controller method sendTestEmail.
@PreAuthorize("isAdmin()")
@ApiOperation(value = "Send a test email", notes = "Sends email to supplied address")
@RequestMapping(method = RequestMethod.PUT, value = "/email/test")
public ResponseEntity<String> sendTestEmail(@RequestParam(value = "email", required = true, defaultValue = "") String email, @RequestParam(value = "username", required = true, defaultValue = "") String username, HttpServletRequest request) {
try {
Translations translations = Common.getTranslations();
Map<String, Object> model = new HashMap<>();
model.put("message", new TranslatableMessage("ftl.userTestEmail", username));
MangoEmailContent cnt = new MangoEmailContent("testEmail", model, translations, translations.translate("ftl.testEmail"), Common.UTF8);
EmailWorkItem.queueEmail(email, cnt);
return new ResponseEntity<String>(new TranslatableMessage("common.testEmailSent", email).translate(Common.getTranslations()), HttpStatus.OK);
} catch (Exception e) {
throw new GenericRestException(HttpStatus.INTERNAL_SERVER_ERROR, e);
}
}
use of com.serotonin.m2m2.email.MangoEmailContent in project ma-modules-public by infiniteautomation.
the class ServerRestController method sendTestEmail.
@ApiOperation(value = "Send a test email", notes = "Sends email to supplied address")
@RequestMapping(method = RequestMethod.PUT, consumes = { "application/json", "text/csv" }, produces = { "application/json", "text/csv" }, value = "/email/test")
public ResponseEntity<String> sendTestEmail(@RequestParam(value = "email", required = true, defaultValue = "") String email, @RequestParam(value = "username", required = true, defaultValue = "") String username, HttpServletRequest request) throws RestValidationFailedException {
RestProcessResult<String> result = new RestProcessResult<String>(HttpStatus.OK);
User user = this.checkUser(request, result);
if (result.isOk()) {
if (Permissions.hasAdmin(user)) {
try {
Translations translations = Common.getTranslations();
Map<String, Object> model = new HashMap<>();
model.put("message", new TranslatableMessage("ftl.userTestEmail", username));
MangoEmailContent cnt = new MangoEmailContent("testEmail", model, translations, translations.translate("ftl.testEmail"), Common.UTF8);
EmailWorkItem.queueEmail(email, cnt);
return result.createResponseEntity(new TranslatableMessage("common.testEmailSent", email).translate(Common.getTranslations()));
} catch (Exception e) {
result.addRestMessage(this.getInternalServerErrorMessage(e.getMessage()));
}
} else {
LOG.warn("Non admin user: " + user.getUsername() + " attempted to send a test email.");
result.addRestMessage(this.getUnauthorizedMessage());
}
}
return result.createResponseEntity();
}
use of com.serotonin.m2m2.email.MangoEmailContent in project ma-core-public by infiniteautomation.
the class MailingListsDwr method sendTestEmail.
@DwrPermission(admin = true)
public ProcessResult sendTestEmail(int id, String name, List<RecipientListEntryBean> entryBeans) {
ProcessResult response = new ProcessResult();
MailingList ml = createMailingList(id, null, name, AlarmLevels.IGNORE, entryBeans);
MailingListDao.instance.populateEntrySubclasses(ml.getEntries());
Set<String> addresses = new HashSet<String>();
ml.appendAddresses(addresses, null);
String[] toAddrs = addresses.toArray(new String[0]);
try {
Translations translations = Common.getTranslations();
Map<String, Object> model = new HashMap<String, Object>();
model.put("message", new TranslatableMessage("ftl.userTestEmail", ml.getName()));
MangoEmailContent cnt = new MangoEmailContent("testEmail", model, translations, translations.translate("ftl.testEmail"), Common.UTF8);
EmailWorkItem.queueEmail(toAddrs, cnt);
} catch (Exception e) {
response.addGenericMessage("mailingLists.testerror", e.getMessage());
log.warn("", e);
}
return response;
}
Aggregations