use of org.springframework.mail.MailException in project molgenis by molgenis.
the class ImportRunService method createAndSendStatusMail.
private void createAndSendStatusMail(ImportRun importRun) {
try {
SimpleMailMessage mailMessage = new SimpleMailMessage();
mailMessage.setTo(userService.getUser(importRun.getUsername()).getEmail());
mailMessage.setSubject(createMailTitle(importRun));
mailMessage.setText(createEnglishMailText(importRun, ZoneId.systemDefault()));
mailSender.send(mailMessage);
} catch (MailException mce) {
LOG.error("Could not send import status mail", mce);
throw new MolgenisDataException("An error occurred. Please contact the administrator.");
}
}
use of org.springframework.mail.MailException in project molgenis by molgenis.
the class AccountServiceImpl method createUser.
@Override
@RunAsSystem
@Transactional
public void createUser(User user, String baseActivationUri) throws UsernameAlreadyExistsException, EmailAlreadyExistsException {
// Check if username already exists
if (userService.getUser(user.getUsername()) != null) {
throw new UsernameAlreadyExistsException("Username '" + user.getUsername() + "' already exists.");
}
// Check if email already exists
if (userService.getUserByEmail(user.getEmail()) != null) {
throw new EmailAlreadyExistsException("Email '" + user.getEmail() + "' is already registered.");
}
// collect activation info
String activationCode = idGenerator.generateId(SECURE_RANDOM);
List<String> activationEmailAddresses;
if (authenticationSettings.getSignUpModeration()) {
activationEmailAddresses = userService.getSuEmailAddresses();
if (activationEmailAddresses == null || activationEmailAddresses.isEmpty())
throw new MolgenisDataException("Administrator account is missing required email address");
} else {
String activationEmailAddress = user.getEmail();
if (activationEmailAddress == null || activationEmailAddress.isEmpty())
throw new MolgenisDataException("User '" + user.getUsername() + "' is missing required email address");
activationEmailAddresses = asList(activationEmailAddress);
}
// create user
user.setActivationCode(activationCode);
user.setActive(false);
dataService.add(USER, user);
LOG.debug("created user " + user.getUsername());
// add user to group
Group group = dataService.query(GROUP, Group.class).eq(NAME, ALL_USER_GROUP).findOne();
GroupMember groupMember = null;
if (group != null) {
groupMember = groupMemberFactory.create();
groupMember.setGroup(group);
groupMember.setUser(user);
dataService.add(GROUP_MEMBER, groupMember);
}
// send activation email
URI activationUri = URI.create(baseActivationUri + '/' + activationCode);
try {
SimpleMailMessage mailMessage = new SimpleMailMessage();
mailMessage.setTo(activationEmailAddresses.toArray(new String[] {}));
mailMessage.setSubject("User registration for " + appSettings.getTitle());
mailMessage.setText(createActivationEmailText(user, activationUri));
mailSender.send(mailMessage);
} catch (MailException mce) {
LOG.error("Could not send signup mail", mce);
if (groupMember != null) {
dataService.delete(GROUP_MEMBER, groupMember);
}
dataService.delete(USER, user);
throw new MolgenisUserException("An error occurred. Please contact the administrator. You are not signed up!");
}
LOG.debug("send activation email for user " + user.getUsername() + " to " + StringUtils.join(activationEmailAddresses, ','));
}
use of org.springframework.mail.MailException in project vaadin-jsf-integration by alejandro-du.
the class PasswordHint method execute.
public String execute() {
getFacesContext().getViewRoot().setViewId("/passwordHint.xhtml");
// ensure that the username has been sent
if (username == null || "".equals(username)) {
log.warn("Username not specified, notifying user that it's a required field.");
addError("errors.required", getText("user.username"));
return null;
} else if (username.endsWith(".xhtml")) {
username = username.substring(0, username.indexOf(".xhtml"));
}
if (log.isDebugEnabled()) {
log.debug("Processing Password Hint...");
}
// look up the user's information
try {
User user = userManager.getUserByUsername(username);
StringBuilder msg = new StringBuilder();
msg.append("Your password hint is: ").append(user.getPasswordHint());
msg.append("\n\nLogin at: ").append(RequestUtil.getAppURL(getRequest()));
message.setTo(user.getEmail());
String subject = '[' + getText("webapp.name") + "] " + getText("user.passwordHint");
message.setSubject(subject);
message.setText(msg.toString());
mailEngine.send(message);
addMessage("login.passwordHint.sent", new Object[] { username, user.getEmail() });
} catch (UsernameNotFoundException e) {
log.warn(e.getMessage());
// If exception is expected do not rethrow
addError("login.passwordHint.error", username);
} catch (MailException me) {
addError(me.getCause().getLocalizedMessage());
}
return "success";
}
use of org.springframework.mail.MailException in project microservices by pwillhan.
the class MailService method sendMailAlert.
@ServiceActivator(inputChannel = "notifyChannel")
public void sendMailAlert(String body) {
String[] parts = body.split("\\|");
String email = parts[0];
String realbody = parts[1];
logger.info("MailService : " + body);
SimpleMailMessage msg = new SimpleMailMessage();
msg.setTo(email);
msg.setFrom(env.getProperty("com.cassandrawebtrader.mail.from"));
msg.setSubject(env.getProperty("com.cassandrawebtrader.mail.subject"));
msg.setText(realbody);
try {
mailSender.send(msg);
logger.info(msg.toString());
} catch (MailException e) {
logger.error(e.getMessage());
}
}
use of org.springframework.mail.MailException in project oc-explorer by devgateway.
the class SendEmailService method sendEmail.
public void sendEmail(final String subject, final String text, final String to) {
SimpleMailMessage msg = new SimpleMailMessage();
msg.setTo(to);
msg.setFrom("support@developmentgateway.org");
msg.setSubject(subject);
msg.setText(text);
try {
LOGGER.info("Sending email " + msg);
javaMailSenderImpl.send(msg);
} catch (MailException e) {
e.printStackTrace();
}
}
Aggregations