From f632e7d7c25d8a86b1f6718f467bfef0d3c09058 Mon Sep 17 00:00:00 2001 From: xinyb <574600396@qq.com> Date: 星期四, 26 九月 2024 18:01:06 +0800 Subject: [PATCH] CRM邮箱功能调整 --- src/com/yc/crm/mail/action/MailAccount.java | 169 ++++++++++++++++++++++++++++++++++++++++++++++++-------- 1 files changed, 144 insertions(+), 25 deletions(-) diff --git a/src/com/yc/crm/mail/action/MailAccount.java b/src/com/yc/crm/mail/action/MailAccount.java index 06b5c95..30a2f3d 100644 --- a/src/com/yc/crm/mail/action/MailAccount.java +++ b/src/com/yc/crm/mail/action/MailAccount.java @@ -61,6 +61,10 @@ msg.setFail("璇疯緭鍏ラ偖绠卞瘑鐮�"); return msg; } + account.setReceiveEmail(account.getEmail()); + account.setReceivePassword(account.getPassword()); + account.setSmtpEmail(account.getEmail()); + account.setSmtpPassword(account.getPassword()); } if (account.getMailType().equals(1) || account.getMailType().equals(2)) { if (StringUtils.isBlank(account.getReceiveProtocol())) { @@ -82,12 +86,6 @@ if (account.getSmtpPort().equals(0)) { msg.setFail("璇疯緭鍏ュ彂閭欢鏈嶅姟鍣ㄧ鍙�"); return msg; - } - if (account.getMailType().equals(1)) { - account.setReceiveEmail(account.getEmail()); - account.setReceivePassword(account.getPassword()); - account.setSmtpEmail(account.getEmail()); - account.setSmtpPassword(account.getPassword()); } if (account.getMailType().equals(2)) { if (StringUtils.isBlank(account.getReceiveEmail())) { @@ -131,6 +129,7 @@ mailAccountIfc.addEmailAccount(account);//娣诲姞鏂扮殑閭閰嶇疆 Map<String, Object> map = new HashMap<>(); if (StringUtils.isBlank(error)) { + map.put("code", 0); map.put("companyId", companyId); map.put("companyName", companyName); map.put("userCode", userCode); @@ -138,6 +137,7 @@ map.put("email", account.getEmail()); msg.setSuccess("宸蹭繚瀛�", map); } else { + map.put("code", -1); map.put("mailStatus", "寮傚父"); map.put("error", error); msg.setSuccess("鎵ц鎴愬姛", map); @@ -189,11 +189,13 @@ Map<String, Object> map = new HashMap<>(); if (StringUtils.isBlank(error)) { mailAccountIfc.updateAliasEmail(aliasEmail, accountId); + map.put("code", 0); map.put("userCode", userCode); map.put("aliasEmail", aliasEmail); map.put("accountId", accountId); msg.setSuccess("宸蹭繚瀛�", map); } else { + map.put("code", -1); map.put("mailStatus", "寮傚父"); map.put("error", error); msg.setSuccess("鎵ц鎴愬姛", map); @@ -286,6 +288,7 @@ String error = emailDetection(account); Map<String, Object> map = new HashMap<>(); if (StringUtils.isBlank(error)) { + map.put("code", 0); map.put("userCode", userCode); map.put("userName", userName); map.put("email", account.getEmail()); @@ -293,6 +296,7 @@ } else { //寮傚父澶勭悊 mailAccountIfc.updateMailStatus("寮傚父", account.getAccountId()); + map.put("code", -1); map.put("mailStatus", "寮傚父"); map.put("error", error); msg.setSuccess("鎵ц鎴愬姛", map); @@ -407,6 +411,52 @@ } /** + * 妫�娴嬬粦瀹氭槸鍚﹀凡缁忓瓨鍦紙鏄惁宸茬粦瀹氾級 + * + * @param email + * @param request + * @param response + * @return + */ + @GetMapping("/eEmailExists.do") + public AllBackMsg eEmailExists(String email, HttpServletRequest request, HttpServletResponse response) { + AllBackMsg msg = new AllBackMsg(); + + try { + HttpSession session = request.getSession(); + String userCode = (String) session.getAttribute(SessionKey.USERCODE); + if (StringUtils.isBlank(userCode)) { + msg.setFail("鐧诲綍鐢ㄦ埛宸茶繃鏈燂紝璇锋鏌�"); + return msg; + } + if (StringUtils.isBlank(email)) { + msg.setFail("閭涓嶈兘涓虹┖"); + return msg; + } + DataSourceEntity dataSource = MultiDataSource.getDataSourceMap(request);//鑾峰彇鏁版嵁婧� + SpObserver.setDBtoInstance("_" + dataSource.getDbId()); + //鏍规嵁褰撳墠鐢ㄦ埛鏌ヨ缁戝畾鐨勯偖绠变俊鎭� + T482102Entity emailEntity = mailAccountIfc.getAccountInfo(userCode, email);//杩斿洖閭鐨勮处鍙蜂俊鎭� + Map<String, Object> map = new HashMap<>(); + if (emailEntity == null || StringUtils.isBlank(emailEntity.getEmail())) { + map.put("code", 0); + map.put("msg", "璇ラ偖绠辨湭缁戝畾"); + } else { + map.put("code", -1); + map.put("msg", "璇ラ偖绠卞凡缁戝畾"); + } + msg.setSuccess("鎵ц鎴愬姛", map); + } catch (MessagingException e) { + msg.setFail(e.getCause() != null ? e.getCause().getMessage() : e.getMessage()); + } catch (Exception e) { + msg.setFail(e.getCause() != null ? e.getCause().getMessage() : e.getMessage()); + } finally { + SpObserver.setDBtoInstance(); + } + return msg; + } + + /** * 妫�娴嬬粦瀹氭槸鍚︽湁鏁� * * @param email @@ -440,7 +490,7 @@ String error = emailDetection(emailEntity); Map<String, Object> map = new HashMap<>(); if (StringUtils.isBlank(error)) { -// map.put("code", "0"); + map.put("code", 0); map.put("email", emailEntity.getEmail()); map.put("protocol", emailEntity.getReceiveProtocol()); map.put("receiveHost", emailEntity.getReceiveHost()); @@ -451,12 +501,12 @@ map.put("smtpPort", emailEntity.getSmtpPort()); map.put("proxyFlag", emailEntity.isProxyFlag()); map.put("biSyncFlag", emailEntity.isBiSyncFlag()); - map.put("mailStatus", emailEntity.getMailStatus()); + map.put("mailStatus", "姝e父"); msg.setSuccess("鎵ц鎴愬姛", map); } else { //寮傚父澶勭悊 mailAccountIfc.updateMailStatus("寮傚父", emailEntity.getAccountId()); -// map.put("code", "-1"); + map.put("code", -1); map.put("mailStatus", "寮傚父"); map.put("error", error); msg.setSuccess("鎵ц鎴愬姛", map); @@ -481,17 +531,30 @@ private String emailDetection(T482102Entity emailEntity) throws MessagingException { String errorMsg = ""; try { + String protocol = emailEntity.getReceiveProtocol().toLowerCase();//鎺ユ敹鍗忚 imap pop3 Properties props = new Properties(); + props.put("mail.store.protocol", protocol);//鎸囧畾鎺ユ敹鐨勯偖浠跺崗璁� IMAP over pop3 + if (protocol.contains("imap")) { + props.put("mail.imaps.host", emailEntity.getReceiveHost()); + props.put("mail.imaps.port", emailEntity.getReceivePort()); + } else if (protocol.contains("pop3")) { + props.put("mail.pop3.host", emailEntity.getReceiveHost()); + props.put("mail.pop3.port", emailEntity.getReceivePort()); + } else { + props.put("mail.imaps.host", emailEntity.getReceiveHost()); + props.put("mail.imaps.port", emailEntity.getReceivePort()); + } +// props.put("mail.imap.ssl.enable", emailEntity.isReceiveSSL()+""); // 浣跨敤 SSL 杩炴帴 +// props.put("mail.imap.starttls.enable", "true");//// IMAP 鍗忚璁剧疆 STARTTLS - props.put("mail.store.protocol", "imaps");//emailEntity.getReceiveProtocol()); // IMAP over SSL - props.put("mail.imaps.host", emailEntity.getReceiveHost()); - props.put("mail.imaps.port", emailEntity.getReceivePort()); - props.put("mail.imaps.starttls.enable", "true");//// IMAP 鍗忚璁剧疆 STARTTLS + props.put("mail.smtp.auth", "true"); + props.put("mail.smtp.ssl.enable", emailEntity.isSmtpSSL() + "");//鍚敤SSL props.put("mail.smtp.host", emailEntity.getSmtpHost()); // 鏇挎崲涓轰綘鐨凷MTP鏈嶅姟鍣� props.put("mail.smtp.port", emailEntity.getSmtpPort()); // 鎴栬�呬綘浣跨敤鐨勭鍙� - props.put("mail.smtp.auth", "true"); - props.put("mail.smtp.starttls.enable", "true");//鍚敤tls - props.put("mail.smtp.ssl.enable", emailEntity.isSmtpSSL() + "");//鍚敤SSL + +// props.put("mail.smtp.starttls.enable", "true");//鍚敤tls +// props.setProperty("mail.smtp.socketFactory.port", "587");//鍚敤tls鍚巔ort:587 + HashMap IAM = new HashMap(); //甯︿笂IMAP ID淇℃伅锛岀敱key鍜寁alue缁勬垚锛屼緥濡俷ame锛寁ersion锛寁endor锛宻upport-email绛夈�� @@ -509,7 +572,7 @@ }); //瀛樺偍瀵硅薄 - IMAPStore store = (IMAPStore) session.getStore(emailEntity.getReceiveProtocol());//imap鍗忚鎴杙op3鍗忚绫诲瀷锛堟帹鑽愪綘浣跨敤IMAP鍗忚鏉ュ瓨鍙栨湇鍔″櫒涓婄殑閭欢銆傦級 + IMAPStore store = (IMAPStore) session.getStore(protocol);//imap鍗忚鎴杙op3鍗忚绫诲瀷锛堟帹鑽愪綘浣跨敤IMAP鍗忚鏉ュ瓨鍙栨湇鍔″櫒涓婄殑閭欢銆傦級 //杩炴帴 store.connect(emailEntity.getReceiveHost(), emailEntity.getReceiveEmail(), emailEntity.getReceivePassword()); store.id(IAM);//163閭闇�瑕侊紝涓嶇劧浼氭姤锛欰3 NO SELECT Unsafe Login. Please contact kefu@188.com for help @@ -521,17 +584,10 @@ folder.close(false); store.close(); - -// Session mailSession = Session.getInstance(props, new Authenticator() { -// @Override -// protected PasswordAuthentication getPasswordAuthentication() { -// return new PasswordAuthentication(emailEntity.getEmail(), emailEntity.getPassword()); -// } -// }); Transport transport = session.getTransport(); transport.connect(); transport.close(); - + mailAccountIfc.updateMailStatus("姝e父", emailEntity.getAccountId()); } catch (MessagingException e) { errorMsg = e.getCause() != null ? e.getCause().getMessage() : e.getMessage(); } catch (Exception e) { @@ -540,6 +596,69 @@ return errorMsg; } + /** + * 甯歌鏌ヨ + * @param request + * @param response + * @return + */ + @GetMapping("/getConvention.do") + public AllBackMsg getConvention(HttpServletRequest request, HttpServletResponse response) { + AllBackMsg msg = new AllBackMsg(); + + try { + HttpSession session = request.getSession(); + String userCode = (String) session.getAttribute(SessionKey.USERCODE); + if (StringUtils.isBlank(userCode)) { + msg.setFail("鐧诲綍鐢ㄦ埛宸茶繃鏈燂紝璇锋鏌�"); + return msg; + } + + DataSourceEntity dataSource = MultiDataSource.getDataSourceMap(request);//鑾峰彇鏁版嵁婧� + SpObserver.setDBtoInstance("_" + dataSource.getDbId()); + //鏍规嵁褰撳墠鐢ㄦ埛鏌ヨ缁戝畾鐨勯偖绠变俊鎭� + + } catch (MessagingException e) { + msg.setFail(e.getCause() != null ? e.getCause().getMessage() : e.getMessage()); + } catch (Exception e) { + msg.setFail(e.getCause() != null ? e.getCause().getMessage() : e.getMessage()); + } finally { + SpObserver.setDBtoInstance(); + } + return msg; + } + + /** + * 甯歌鏇存柊 + * @param request + * @param response + * @return + */ + @GetMapping("/updateConvention.do") + public AllBackMsg updateConvention(HttpServletRequest request, HttpServletResponse response) { + AllBackMsg msg = new AllBackMsg(); + try { + HttpSession session = request.getSession(); + String userCode = (String) session.getAttribute(SessionKey.USERCODE); + if (StringUtils.isBlank(userCode)) { + msg.setFail("鐧诲綍鐢ㄦ埛宸茶繃鏈燂紝璇锋鏌�"); + return msg; + } + + DataSourceEntity dataSource = MultiDataSource.getDataSourceMap(request);//鑾峰彇鏁版嵁婧� + SpObserver.setDBtoInstance("_" + dataSource.getDbId()); + //鏍规嵁褰撳墠鐢ㄦ埛鏌ヨ缁戝畾鐨勯偖绠变俊鎭� + + } catch (MessagingException e) { + msg.setFail(e.getCause() != null ? e.getCause().getMessage() : e.getMessage()); + } catch (Exception e) { + msg.setFail(e.getCause() != null ? e.getCause().getMessage() : e.getMessage()); + } finally { + SpObserver.setDBtoInstance(); + } + return msg; + } + private T482102Entity getMailConfigProperties(T482102Entity t482102) { try { String email = t482102.getEmail(); -- Gitblit v1.8.0