use of org.apache.commons.mail.EmailException in project AuthMeReloaded by AuthMe.
the class TestEmailSender method sendTestEmail.
private boolean sendTestEmail(String email) {
HtmlEmail htmlEmail;
try {
htmlEmail = sendMailSsl.initializeMail(email);
} catch (EmailException e) {
ConsoleLogger.logException("Failed to create email for sample email:", e);
return false;
}
htmlEmail.setSubject("AuthMe test email");
String message = "Hello there!<br />This is a sample email sent to you from a Minecraft server (" + server.getName() + ") via /authme debug mail. If you're seeing this, sending emails should be fine.";
return sendMailSsl.sendEmail(message, htmlEmail);
}
use of org.apache.commons.mail.EmailException in project sling by apache.
the class SimpleMailService method sendMail.
private MailResult sendMail(final String message, final String recipient, final Map data, final MailBuilder mailBuilder) {
try {
final Email email = mailBuilder.build(message, recipient, data);
final String messageId = email.send();
logger.info("mail '{}' sent", messageId);
final byte[] bytes = MailUtil.toByteArray(email);
return new MailResult(bytes);
} catch (EmailException | MessagingException | IOException e) {
throw new CompletionException(e);
}
}
use of org.apache.commons.mail.EmailException in project dal by ctripcorp.
the class GenTaskResource method taskApproveOperationForEmail.
@GET
@Path("taskApproveOperationForEmail")
@Produces(MediaType.APPLICATION_JSON)
public String taskApproveOperationForEmail(@Context HttpServletRequest request, @QueryParam("taskId") int taskId, @QueryParam("taskType") String taskType, @QueryParam("approveFlag") int approveFlag, @QueryParam("approveMsg") String approveMsg) {
String userNo = RequestUtil.getUserNo(request);
LoginUser user = SpringBeanGetter.getDaoOfLoginUser().getUserByNo(userNo);
if (user == null) {
return "please login fisrt.";
}
ApproveTask task = haveApprovePermision(user.getId(), taskId, taskType);
if (task == null) {
return "Dao have been approved.";
}
List<GenTaskByTableViewSp> tableViewSpTasks = new ArrayList<>();
List<GenTaskBySqlBuilder> autoTasks = new ArrayList<>();
List<GenTaskByFreeSql> sqlTasks = new ArrayList<>();
if ("table_view_sp".equalsIgnoreCase(taskType)) {
SpringBeanGetter.getDaoByTableViewSp().updateTask(taskId, approveFlag, approveMsg);
SpringBeanGetter.getApproveTaskDao().deleteApproveTaskByTaskIdAndType(taskId, taskType);
tableViewSpTasks.add(SpringBeanGetter.getDaoByTableViewSp().getTasksByTaskId(taskId));
} else if ("auto".equalsIgnoreCase(taskType)) {
SpringBeanGetter.getDaoBySqlBuilder().updateTask(taskId, approveFlag, approveMsg);
SpringBeanGetter.getApproveTaskDao().deleteApproveTaskByTaskIdAndType(taskId, taskType);
autoTasks.add(SpringBeanGetter.getDaoBySqlBuilder().getTasksByTaskId(taskId));
} else if ("sql".equalsIgnoreCase(taskType)) {
SpringBeanGetter.getDaoByFreeSql().updateTask(taskId, approveFlag, approveMsg);
SpringBeanGetter.getApproveTaskDao().deleteApproveTaskByTaskIdAndType(taskId, taskType);
sqlTasks.add(SpringBeanGetter.getDaoByFreeSql().getTasksByTaskId(taskId));
}
java.util.Collections.sort(tableViewSpTasks);
java.util.Collections.sort(autoTasks);
java.util.Collections.sort(sqlTasks);
LoginUser noticeUsr = SpringBeanGetter.getDaoOfLoginUser().getUserById(task.getCreate_user_id());
VelocityContext context = GenUtils.buildDefaultVelocityContext();
context.put("standardDao", tableViewSpTasks);
context.put("autoDao", autoTasks);
context.put("sqlDao", sqlTasks);
String msg = "你好," + noticeUsr.getUserName() + ":<br/> 你提交的DAO已审批,审批";
if (approveFlag == 2) {
msg += "通过。";
} else {
msg += "未通过。";
}
if (approveMsg != null) {
msg += "<br/> 审批意见:" + approveMsg;
}
context.put("msg", msg);
String mailMsg = GenUtils.mergeVelocityContext(context, "templates/approval/approveResult.tpl");
HtmlEmail email = new HtmlEmail();
email.setHostName(Configuration.get("email_host_name"));
email.setAuthentication(Configuration.get("email_user_name"), Configuration.get("email_password"));
try {
email.addTo(noticeUsr.getUserEmail());
email.setFrom(user.getUserEmail(), user.getUserName());
email.setSubject("Codegen DAO 审批结果通知");
email.setHtmlMsg(mailMsg);
email.send();
} catch (EmailException e) {
e.printStackTrace();
}
return "Success Approved.";
}
use of org.apache.commons.mail.EmailException in project dhis2-core by dhis2.
the class EmailMessageSender method sendMessage.
@Override
public OutboundMessageResponse sendMessage(String subject, String text, Set<String> recipients) {
EmailConfiguration emailConfig = getEmailConfiguration();
String errorMessage = "No recipient found";
OutboundMessageResponse status = new OutboundMessageResponse();
if (emailConfig.getHostName() == null) {
status.setOk(false);
status.setResponseObject(EmailResponse.NOT_CONFIGURED);
return status;
}
try {
HtmlEmail email = getHtmlEmail(emailConfig.getHostName(), emailConfig.getPort(), emailConfig.getUsername(), emailConfig.getPassword(), emailConfig.isTls(), emailConfig.getFrom());
email.setSubject(customizeTitle(DEFAULT_SUBJECT_PREFIX) + subject);
email.setTextMsg(text);
boolean hasRecipients = false;
for (String recipient : recipients) {
if (isEmailValid(recipient)) {
email.addBcc(recipient);
hasRecipients = true;
log.info("Sending email to : " + recipient + " to host: " + emailConfig.getHostName() + ":" + emailConfig.getPort());
} else {
log.error(recipient + " is not a valid email");
errorMessage = "No valid email address found";
}
}
if (hasRecipients) {
email.send();
log.info("Email sent using host: " + emailConfig.getHostName() + ":" + emailConfig.getPort() + " with TLS: " + emailConfig.isTls());
return new OutboundMessageResponse("Email sent", EmailResponse.SENT, true);
} else {
status = new OutboundMessageResponse(errorMessage, EmailResponse.ABORTED, false);
}
} catch (EmailException ex) {
log.warn("Error while sending email: " + ex.getMessage() + ", " + DebugUtils.getStackTrace(ex));
status = new OutboundMessageResponse("Email not sent: " + ex.getMessage(), EmailResponse.FAILED, false);
} catch (RuntimeException ex) {
log.warn("Error while sending email: " + ex.getMessage() + ", " + DebugUtils.getStackTrace(ex));
status = new OutboundMessageResponse("Email not sent: " + ex.getMessage(), EmailResponse.FAILED, false);
}
return status;
}
Aggregations