* @throws IOException
*/
@RequestMapping(value = "/sendemail.jspx")
String sendemail(HttpServletRequest request, HttpServletResponse response)
throws IOException {
User user = (User) request.getSession().getAttribute("userLogin");
String email = request.getParameter("email");
String password = request.getParameter("password");
String actId = request.getParameter("actId");
String op = request.getParameter("op");
String[] toAddresses = request.getParameterValues("toAddresses");
String smtpHost = EmailConfig.getValue("smtpHost");
String needAuth = EmailConfig.getValue("needAuth");
Page rp = userService.listAllUser(1);
Activity act = activityService.getActivity(Integer.valueOf(actId));
// 返回页面
if (WebUtils.isEmptyString(email) || null == act) {
request.setAttribute("actMsg", (null == act) ? "找不到该活动!" : "操作成功!");
request.setAttribute("email", user.getEmail());
request.setAttribute("actId", actId);
request.setAttribute("list", rp);
request.setAttribute("op", op);
request.setAttribute("smtpHost", smtpHost);
request.setAttribute("needAuth", needAuth);
return "activity/sendemail";
}
// 发送邮件
boolean flag = false;
Mail mail = new Mail(email, password);
try {
if ("add".equals(op)) {
mail.send(
email,
toAddresses,
null,
"活动通知",
EmailTemplates.buildAddContent(act.getTime(),
act.getTitle(), act.getId()));
} else if ("edit".equals(op)) {
mail.send(
email,
toAddresses,
null,
"活动修改通知",
EmailTemplates.buildEditContent(act.getTime(),
act.getTitle(),
EmailConfig.getValue("editContent"),
act.getId()));
} else if ("cancel".equals(op)) {
mail.send(
email,
toAddresses,
null,
"活动取消通知",
EmailTemplates.buildCancelContent(act.getTime(),
act.getTitle()));
}
flag = true;
} catch (Exception e) {
e.printStackTrace();
}
// 发送邮件失败
if (!flag) {
request.setAttribute("actMsg", "发送邮件失败!");
request.setAttribute("email", user.getEmail());
request.setAttribute("actId", actId);
request.setAttribute("list", rp);
request.setAttribute("op", op);
request.setAttribute("smtpHost", smtpHost);
request.setAttribute("needAuth", needAuth);