예제 #1
0
 @Override
 public String query(
     MailsHistory model, Integer page, Integer rows, Date startDate, Date endDate) {
   List<MailsHistory> list = mailsHistoryDAO.query(model, page, rows, startDate, endDate);
   Long total = mailsHistoryDAO.getTotalCount(model, startDate, endDate);
   String[] properties = {
     "mailsHistoryId", "teacher.teacherName", "receiveIDs", "title", "content", "sendTime"
   };
   return JSONUtil.toJson(list, properties, total);
 }
예제 #2
0
  @Override
  public ServiceResult send(String toMailAddr, String subject, String content, Integer mailType) {
    ServiceResult result = new ServiceResult(false);
    MimeMessage mailMessage = mailSender.createMimeMessage();
    // 设置utf-8或GBK编码,否则邮件会有乱码
    MimeMessageHelper messageHelper = null;
    // 设置邮件参数
    SystemConfig systemConfig = systemConfigDAO.load(1);
    try {
      messageHelper = new MimeMessageHelper(mailMessage, true, "utf-8");
      messageHelper.setFrom(
          systemConfig.getEmailCode(),
          systemConfig.getCompanyName()); // 发送者,这里还可以另起Email别名,不用和xml里的username一致
      messageHelper.setTo(toMailAddr); // 接受者
      messageHelper.setSubject(subject); // 主题
      messageHelper.setText(content, true); // 邮件内容
      mailSender.send(mailMessage);
    } catch (Exception e) {
      throw new RuntimeException(e.getMessage());
    }

    MailsHistory mailsHistory = new MailsHistory();
    mailsHistory.setTitle(subject);
    mailsHistory.setContent(content);
    mailsHistory.setReceiveIDs(toMailAddr);
    mailsHistory.setMailType(mailType);
    mailsHistoryDAO.save(mailsHistory);

    result.setIsSuccess(true);
    return result;
  }