| | |
| | | } |
| | | |
| | | /** |
| | | * 获取待处理邮件列表 |
| | | * |
| | | * @return |
| | | */ |
| | | @GetMapping("/getHandleMailList.do") |
| | | public AllBackMsg getHandleMailList(String mail, HttpServletRequest request, HttpServletResponse response) throws Exception { |
| | | AllBackMsg msg = new AllBackMsg(); |
| | | try { |
| | | if (StringUtils.isNotBlank(mail)) { |
| | | if (!EMAIL_PATTERN.matcher(mail).matches()) { |
| | | msg.setFail("邮箱的各式不争取"); |
| | | return msg; |
| | | } |
| | | } |
| | | HttpSession session = request.getSession(); |
| | | String userCode = (String) session.getAttribute(SessionKey.USERCODE);//当前登录用户 |
| | | if (StringUtils.isBlank(userCode)) {//获取不到当前用户直接结束 |
| | | msg.setFail("获取不到用户信息"); |
| | | return msg; |
| | | } |
| | | DataSourceEntity dataSourceEntity = MultiDataSource.getDataSourceMap(request);//获取数据源信息 |
| | | SpObserver.setDBtoInstance("_" + dataSourceEntity.getDbId());//切换数据源 |
| | | List<t482101HList> t482101HEntityList = emailIfc.getHandleMailList(mail, userCode); |
| | | if (t482101HEntityList.size() > 0) { |
| | | msg.setSuccess("执行完成", t482101HEntityList); |
| | | } |
| | | } catch (Exception e) { |
| | | msg.setFail(e.getCause() != null ? e.getCause().getMessage() : e.getMessage()); |
| | | } finally { |
| | | SpObserver.setDBtoInstance(); |
| | | } |
| | | return msg; |
| | | } |
| | | |
| | | /** |
| | | * 获取邮件详情 |
| | | * |
| | | * @return |
| | |
| | | List<String> list = new ArrayList<>(); |
| | | if (attachmentEntities.size() > 0) { |
| | | for (AttachmentEntity a : attachmentEntities) { |
| | | list.add(shoppingImageServer + "/uploads/attachment/"+dataSourceEntity.getDbId()+"/482101/" + a.getUnid() + "@p@" + a.getPhysicalFile()); |
| | | list.add(shoppingImageServer + "/uploads/attachment/" + dataSourceEntity.getDbId() + "/482101/" + a.getUnid() + "@p@" + a.getPhysicalFile()); |
| | | } |
| | | t482101HEntity.setAttachmentPath(list); |
| | | } |
| | |
| | | } |
| | | |
| | | /** |
| | | * 快速回复 |
| | | * |
| | | * @return |
| | | */ |
| | | @PostMapping("/setQuickReply.do") |
| | | public AllBackMsg setQuickReply(@RequestBody Map<String, Object> reply, HttpServletRequest request, HttpServletResponse response) throws Exception { |
| | | AllBackMsg msg = new AllBackMsg(); |
| | | try { |
| | | if (reply.get("docCode") == null) { |
| | | msg.setFail("获取不到回复邮件的唯一docCode值"); |
| | | return msg; |
| | | } |
| | | if (reply.get("content") == null) { |
| | | msg.setFail("请输入回复内容"); |
| | | return msg; |
| | | } |
| | | HttpSession session = request.getSession(); |
| | | String userCode = (String) session.getAttribute(SessionKey.USERCODE);//当前登录用户 |
| | | if (StringUtils.isBlank(userCode)) {//获取不到当前用户直接结束 |
| | | msg.setFail("获取不到用户信息"); |
| | | return msg; |
| | | } |
| | | String docCode = (String) reply.get("docCode");//编号 |
| | | String content = (String) reply.get("content");//内容 |
| | | Integer count = mailServiceIfc.setQuickReply(docCode, content); |
| | | Map<String, Object> map = new HashMap<>(); |
| | | if (count.equals(1)) { |
| | | map.put("code", 0); |
| | | map.put("docCode", docCode); |
| | | map.put("msg", "邮件已回复"); |
| | | msg.setSuccess("执行成功", map); |
| | | } else { |
| | | map.put("code", -1); |
| | | map.put("docCode", docCode); |
| | | map.put("msg", "邮件回复失败"); |
| | | msg.setSuccess("执行成功", map); |
| | | } |
| | | } catch (Exception e) { |
| | | msg.setFail(e.getCause() != null ? e.getCause().getMessage() : e.getMessage()); |
| | | } finally { |
| | | SpObserver.setDBtoInstance(); |
| | | } |
| | | return msg; |
| | | } |
| | | |
| | | /** |
| | | * 保存草稿箱(保存或修改) |
| | | * |
| | | * @return |
| | |
| | | private Integer mailType;// [note: '0:草稿箱1:收件箱2:发件箱'] |
| | | private String senderName;//发件人名称 |
| | | private String sender;// [note:'发送人'] |
| | | private List<String> receiver = new ArrayList<>(); |
| | | private List<String> receiver = new ArrayList<>();//收件人集合 |
| | | private Integer folderId = 0;// [note:'文件夹id'] |
| | | private Integer deleteFlag = 0; //[note:'是否已删除'] |
| | | private Integer readFlag = 0;// [note:'是否已读'] |
| | |
| | | List<t482101HList> getReceivingMailList(String email, Integer mailType, boolean isNoRead, String userCode); |
| | | |
| | | /** |
| | | * 获取待处理邮件列表 |
| | | * @param email |
| | | * @return |
| | | */ |
| | | List<t482101HList> getHandleMailList(String email,String userCode); |
| | | |
| | | /** |
| | | * 获取用户的全部邮件 |
| | | * |
| | | * @param userCode |
| | |
| | | "@physicalFile varchar(50),@OriginalPicture varbinary(max) \n"; |
| | | sql += "exec sp_newdoccode 482101," + GridUtils.prossSqlParm(m.getUserCode()) + ",@docCode output \n"; |
| | | sql += "insert into t482101H(companyId,companyName,formId,docCode,docdate,PeriodID,postCode,postname,mailType,senderName,sender,receiver," + |
| | | "cc,bcc,subject,userCode,userName,content,plain_text,messageId,read_flag,delete_flag,create_time,update_time,receive_time," + |
| | | "cc,bcc,subject,userCode,userName,content,plain_text,messageId,read_flag,delete_flag,create_time,update_time," +//receive_time |
| | | "attach_flag,attachment_list) values "; |
| | | sql += "(" + GridUtils.prossSqlParm(m.getCompanyId()) + "," + GridUtils.prossSqlParm(m.getCompanyName()) + ",482101," + |
| | | "@docCode,convert(varchar(10),getdate(),120),convert(varchar(7),getdate(),120)," |
| | |
| | | GridUtils.prossSqlParm(StringUtils.join(m.getBcc(), ",")) + "," + |
| | | GridUtils.prossSqlParm(m.getSubject()) + "," + GridUtils.prossSqlParm(m.getUserCode()) + "," + GridUtils.prossSqlParm(m.getUserName()) + "," + |
| | | GridUtils.prossSqlParm(m.getContent()) + "," + GridUtils.prossSqlParm(m.getPlainText()) + "," + GridUtils.prossSqlParm(m.getMessageId()) + "," + |
| | | m.getReadFlag() + "," + m.getDeleteFlag() + ",getdate(),getdate()," + GridUtils.prossSqlParm(m.getReceiveTime()) + "," + m.getAttachFlag() + "," + |
| | | GridUtils.prossSqlParm(m.getAttachmentList()) + ") \n" + |
| | | m.getReadFlag() + "," + m.getDeleteFlag() + ",getdate(),getdate()," + m.getAttachFlag() + "," + GridUtils.prossSqlParm(m.getAttachmentList()) + ") \n" + |
| | | mailFileSql(m.getMailFile()); |
| | | sql += "select @docCode as docCode"; |
| | | String docCode = jdbcTemplate.queryForObject(sql, String.class); |
| | |
| | | for (t482101HEntity m : mail) {//遍历内容 |
| | | sql += "exec sp_newdoccode 482101," + GridUtils.prossSqlParm(m.getUserCode()) + ",@docCode output \n"; |
| | | sql += "insert into t482101H(companyId,companyName,formId,docCode,docdate,PeriodID,postCode,postname,mailType,senderName,sender,receiver," + |
| | | "cc,bcc,subject,userCode,userName,content,plain_text,messageId,read_flag,delete_flag,create_time,update_time,receive_time," + |
| | | "cc,bcc,subject,userCode,userName,content,plain_text,messageId,read_flag,delete_flag,create_time,update_time," + |
| | | "attach_flag,attachment_list) values "; |
| | | sql += "(" + GridUtils.prossSqlParm(m.getCompanyId()) + "," + GridUtils.prossSqlParm(m.getCompanyName()) + ",482101," + |
| | | "@docCode,convert(varchar(10),getdate(),120),convert(varchar(7),getdate(),120)," |
| | |
| | | GridUtils.prossSqlParm(StringUtils.join(m.getBcc(), ",")) + "," + |
| | | GridUtils.prossSqlParm(m.getSubject()) + "," + GridUtils.prossSqlParm(m.getUserCode()) + "," + GridUtils.prossSqlParm(m.getUserName()) + "," + |
| | | GridUtils.prossSqlParm(m.getContent()) + "," + GridUtils.prossSqlParm(m.getPlainText()) + "," + GridUtils.prossSqlParm(m.getMessageId()) + "," + |
| | | m.getReadFlag() + "," + m.getDeleteFlag() + ",getdate(),getdate()," + GridUtils.prossSqlParm(m.getReceiveTime()) + "," + |
| | | m.getAttachFlag() + "," + GridUtils.prossSqlParm(m.getAttachmentList()) + ") \n" + |
| | | m.getReadFlag() + "," + m.getDeleteFlag() + ",getdate(),getdate()," + m.getAttachFlag() + "," + GridUtils.prossSqlParm(m.getAttachmentList()) + ") \n" + |
| | | mailFileSql(m.getMailFile()); |
| | | } |
| | | jdbcTemplate.update(sql); |
| | |
| | | } |
| | | |
| | | @Override |
| | | public List<t482101HList> getHandleMailList(String email, String userCode) { |
| | | String sql = "set nocount on\n"; |
| | | try { |
| | | sql += "select companyId,companyName,mailType,DocCode,senderName,sender,receiver,subject,plain_text," + |
| | | "receive_time,update_time,create_time,senderName,sender,userCode,userName,folder_id,delete_Flag, " + |
| | | "read_Flag,(case when (isnull(handle_time,'') <> '' and isnull(handle_time,'') < getdate()) then 1 else 0 end) as handle," + |
| | | "handle_time from t482101H "; |
| | | sql += " where isnull(handle_time,'') <> '' and isnull(handle_time,'') < getdate()"; |
| | | sql += " and userCode=" + GridUtils.prossSqlParm(userCode) + " and receiver like '%" + email + "%'"; |
| | | return jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(t482101HList.class)); |
| | | } catch (Exception e) { |
| | | throw e; |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public List<t482101HList> getUserMailList(String userCode) { |
| | | String sql = " set nocount on \n"; |
| | | try { |
| | |
| | | throw e; |
| | | } |
| | | } |
| | | |
| | | @Transactional(rollbackFor = Exception.class) |
| | | @Override |
| | | public void updateRead(String docCode, boolean status) { |
| | |
| | | throw e; |
| | | } |
| | | } |
| | | |
| | | @Transactional(rollbackFor = Exception.class) |
| | | @Override |
| | | public void updateMailHandle(String handleTime, String docCode) { |
| | |
| | | * @throws IOException |
| | | */ |
| | | abstract void sendEmails(t482101HEntity t482101H, HttpServletRequest request) throws Exception; |
| | | |
| | | /** |
| | | * 快速回复 |
| | | * @param docCode |
| | | * @param content |
| | | * @return |
| | | */ |
| | | Integer setQuickReply(String docCode,String content) throws MessagingException; |
| | | } |
| | |
| | | String pwd = emailEntity.getReceivePassword();//密码 |
| | | |
| | | Properties properties = new Properties(); |
| | | properties.put("mail.store.protocol", protocol); // IMAP over SSL |
| | | properties.setProperty("mail.store.protocol", protocol); // IMAP over SSL |
| | | if (protocol.contains("imap")) {//接收协议imap |
| | | properties.put("mail.imaps.host", server); |
| | | properties.put("mail.imaps.port", port); |
| | | properties.setProperty("mail.imaps.host", server); |
| | | properties.setProperty("mail.imaps.port", port + ""); |
| | | } else if (protocol.contains("pop3")) {//接收协议pop3 |
| | | properties.put("mail.pop3.host", server); |
| | | properties.put("mail.pop3.port", port); |
| | | properties.setProperty("mail.pop3.host", server); |
| | | properties.setProperty("mail.pop3.port", port + ""); |
| | | } else {//其他(再加) |
| | | properties.put("mail.imaps.host", server); |
| | | properties.put("mail.imaps.port", port); |
| | | properties.setProperty("mail.imaps.host", server); |
| | | properties.setProperty("mail.imaps.port", port + ""); |
| | | } |
| | | // properties.put("mail.imaps.starttls.enable", "true");//// IMAP 协议设置 STARTTLS |
| | | |
| | |
| | | Properties properties = new Properties(); |
| | | properties.setProperty("mail.smtp.auth", "true");// // 设置SMTP是否需要认证 指定客户端是否向邮件服务器提交认证 |
| | | properties.setProperty("mail.transport.protocol", "smtp");//设置传输协议 指定采用的邮件发送协议。 |
| | | properties.put("mail.smtp.ssl.enable", emailEntity.isSmtpSSL() + "");// // 设置启用SSL加密 |
| | | properties.setProperty("mail.smtp.ssl.enable", emailEntity.isSmtpSSL() + "");// // 设置启用SSL加密 |
| | | properties.setProperty("mail.smtp.host", emailEntity.getSmtpHost()); |
| | | properties.setProperty("mail.smtp.port", emailEntity.getSmtpPort() + ""); |
| | | |
| | |
| | | MimeMessage message = new MimeMessage(session); |
| | | message.setFrom(new InternetAddress(sendEmail)); |
| | | message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(recipientEmail)); |
| | | message.setSubject(t482101H.getSubject()); |
| | | message.setSubject(t482101H.getSubject());//主题 |
| | | |
| | | String Unique_ID = "<onBus_" + UUID.randomUUID().toString().toUpperCase() + "@mail.com>";//系统单号唯一码 |
| | | message.setHeader("Message-ID", Unique_ID);//系统内部唯一码 |
| | |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public Integer setQuickReply(String docCode, String content) throws MessagingException { |
| | | String sql = "set nocount on\n"; |
| | | try { |
| | | sql += "declare @docCode varchar(200) ='" + docCode + "'\n"; |
| | | sql += "update t482101H set receive_time=getdate() where docCode=@docCode\n";//更新回复时间 |
| | | sql += "select a.subject,a.sender,a.receiver,a.messageid,b.smtpEmail,b.smtpPassword,b.smtpHost,b.smtpPort,isnull(b.smtpSSL,0) as smtpSSL " + |
| | | " from t482101H a join t482102 b on a.receiver=b.smtpEmail where docCode=@docCode"; |
| | | Map<String, Object> map = jdbcTemplate.queryForMap(sql); |
| | | if (map == null || map.get("sender") == null) { |
| | | throw new MessagingException("回复人信息查找不到,请检查docCode唯一码"); |
| | | } |
| | | String receiver = (String) map.get("sender");//收件人 |
| | | String sender = (String) map.get("receiver");//发件人 |
| | | String smtpSSL = map.get("smtpSSL").equals(0) ? "false" : "true"; |
| | | |
| | | Properties props = new Properties(); |
| | | props.setProperty("mail.smtp.auth", "true"); |
| | | props.setProperty("mail.transport.protocol", "smtp");//设置传输协议 指定采用的邮件发送协议。 |
| | | props.setProperty("mail.smtp.ssl.enable", smtpSSL);// // 设置启用SSL加密 |
| | | props.setProperty("mail.smtp.host", (String) map.get("smtpHost")); |
| | | props.setProperty("mail.smtp.port", map.get("smtpPort") + ""); |
| | | // props.setProperty("mail.smtp.starttls.enable", "true"); |
| | | |
| | | Session session = Session.getInstance(props, new javax.mail.Authenticator() { |
| | | protected PasswordAuthentication getPasswordAuthentication() { |
| | | return new PasswordAuthentication((String) map.get("smtpEmail"), (String) map.get("smtpPassword")); |
| | | } |
| | | }); |
| | | |
| | | Message replyMessage = new MimeMessage(session); |
| | | replyMessage.setFrom(new InternetAddress(sender)); |
| | | replyMessage.setRecipients(Message.RecipientType.TO, InternetAddress.parse(receiver));//收件人 |
| | | replyMessage.setSubject("Re: " + map.get("subject"));//主题 |
| | | |
| | | // 引用原邮件 |
| | | replyMessage.setHeader("In-Reply-To", (String) map.get("messageid")); |
| | | replyMessage.setHeader("References", (String) map.get("messageid")); |
| | | |
| | | replyMessage.setText(content);//这里是回复的内容 |
| | | |
| | | Transport.send(replyMessage); |
| | | |
| | | return 1; |
| | | } catch (MessagingException e) { |
| | | throw new MessagingException("快速回复异常:" + e.getMessage()); |
| | | } catch (Exception e) { |
| | | throw e; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 收件箱返回的信息进行封装处理 |
| | | * |
| | |
| | | * @throws MessagingException |
| | | * @throws IOException |
| | | */ |
| | | public void setMailContent(Message[] messages, T482102Entity email, FoundationEntity foundation) throws Exception { |
| | | public void setMailContent(Message[] messages, T482102Entity email, FoundationEntity foundation) throws |
| | | Exception { |
| | | try { |
| | | List<t482101HEntity> t482101HEntityList = new ArrayList<>(); |
| | | List<String> messageIdList = mailIfc.getMessageIdList(email.getReceiveEmail());//存在系统表里的邮件 |
| | |
| | | * @throws Exception |
| | | */ |
| | | // 辅助方法,用于递归获取纯文本邮件内容 |
| | | private String getTextFromMimeMultipart(MimeMultipart mimeMultipart, StringBuilder plainText, List<MailFileEntity.MailBodyPart> part, String unId, StringBuilder attachment) throws Exception { |
| | | private String getTextFromMimeMultipart(MimeMultipart mimeMultipart, StringBuilder |
| | | plainText, List<MailFileEntity.MailBodyPart> part, String unId, StringBuilder attachment) throws Exception { |
| | | int count = mimeMultipart.getCount(); |
| | | if (count == 0) { |
| | | throw new MessagingException("Multipart with no body parts"); |
| | |
| | | String nextResult = result.toString(); |
| | | if (nextResult.contains(cId)) {//有嵌套内容 |
| | | //替换 |
| | | nextResult = nextResult.replace("cid:" + cId + "", shoppingImageServer + "/uploads/attachment/82/482101/" + unId + "@p@" + p.getPhysicalFile()); |
| | | nextResult = nextResult.replace("cid:" + cId + "", shoppingImageServer + "/mail/attachment/82/482101/" + unId + "@p@" + p.getPhysicalFile()); |
| | | result.setLength(0);//清空先 |
| | | result.append(nextResult); |
| | | } |