| | |
| | | import com.whyc.util.ActionUtil; |
| | | import com.whyc.util.MailUtil; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.mail.MailException; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | |
| | | public Response sendMail(MailDTO mailDTO) { |
| | | Long uId = ActionUtil.getUser().getId(); |
| | | String name=ActionUtil.getUser().getName(); |
| | | //日志内容准备 |
| | | StringBuilder mailUserStr = new StringBuilder(); |
| | | List<String> mailList = mailDTO.getMailList(); |
| | | for (int i = 0; i < mailList.size(); i++) { |
| | | if(i==0){ |
| | | mailUserStr.append(mailList.get(i)); |
| | | }else{ |
| | | mailUserStr.append(","+mailList.get(i)); |
| | | } |
| | | } |
| | | try { |
| | | mailUtil.sendMailBatch(name,mailDTO.getMailList(),mailDTO.getTitle(),mailDTO.getContent()); |
| | | |
| | | //日志 |
| | | List<String> mailList = mailDTO.getMailList(); |
| | | for (int i = 0; i < mailList.size(); i++) { |
| | | if(i==0){ |
| | | mailUserStr.append(mailList.get(i)); |
| | | }else{ |
| | | mailUserStr.append(","+mailList.get(i)); |
| | | } |
| | | } |
| | | |
| | | String msgDetail = "发送给邮箱" + mailUserStr + ",标题为:" + mailDTO.getTitle() + ",内容为:" + mailDTO.getContent(); |
| | | logService.record(uId, name, UserOperation.TYPE_SEND_MAIL.getType(), "邮件发送", msgDetail); |
| | | return new Response().set(1,true,"发送完成"); |
| | | } catch (MessagingException ex) { //邮件发送异常,存入数据库待重新发送列表 |
| | | } catch (MessagingException | MailException ex) { //邮件发送异常,存入数据库待重新发送列表 |
| | | MailQueue queue = new MailQueue(); |
| | | queue.setMails(mailUserStr.toString()); |
| | | queue.setTitle(mailDTO.getTitle()); |
| | |
| | | mailQueueService.deleteById(queue.getId()); |
| | | //日志 |
| | | String msgDetail = "发送给邮箱" + mails + ",标题为:" + queue.getTitle() + ",内容为:" + queue.getContent(); |
| | | logService.record(uId, name, UserOperation.TYPE_SEND_MAIL.getType(), "邮件发送", msgDetail); |
| | | } catch (MessagingException ex) { //邮件发送异常 |
| | | logService.record(uId, name, UserOperation.TYPE_SEND_MAIL.getType(), "邮件因网络问题由系统延时发送", msgDetail); |
| | | } catch (MessagingException | MailException ex) { //邮件发送异常 |
| | | //System.out.println("邮件发送异常,后续会持续发送直到成功"); |
| | | } |
| | | } |