1package com.flysand; 2 3import com.alibaba.fastjson.JSON; 4import com.google.common.collect.Lists; 5import com.j1cn.bizclient.meta.entity.email.EmailEntity; 6import com.j1cn.bizclient.meta.entity.email.EmailInfo; 7import com.j1cn.bizclient.meta.entity.email.ReceiveEntity; 8import com.j1cn.commons.exception.JyException; 9import com.j1cn.commons.utils.StringUtils; 10import com.sun.net.ssl.internal.ssl.Provider; 11import org.slf4j.Logger; 12import org.slf4j.LoggerFactory; 13import org.springframework.util.CollectionUtils; 14 15import javax.activation.DataHandler; 16import javax.activation.DataSource; 17import javax.activation.FileDataSource; 18import javax.mail.*; 19import javax.mail.internet.*; 20import javax.mail.util.ByteArrayDataSource; 21import java.io.File; 22import java.io.IOException; 23import java.io.InputStream; 24import java.security.Security; 25import java.util.Date; 26import java.util.List; 27import java.util.Properties; 28import java.util.Vector; 29 30/** 31 * 邮件工具类 32 * 33 * @author flysand 34 **/ 35public class EmailUtils { 36 37 private static final Logger logger = LoggerFactory.getLogger(EmailUtils.class); 38 39 private static final String MAIL_SMTP_AUTH = "mail.smtp.auth"; 40 private static final String MAIL_TRANSPORT_PROTOCOL = "mail.transport.protocol"; 41 private static final String MAIL_SMTP_HOST = "mail.smtp.host"; 42 43 private static final String TEXT = "TEXT"; 44 45 private static final String TEXT_PLAIN = "TEXT/PLAIN"; 46 47 private static final String TEXT_HTML = "TEXT/HTML"; 48 49 private static final String INVALID_ADDRESS_MESSAGE = "Invalid Addresses"; 50 51 52 public static void sendAttachMail(EmailEntity emailEntity, InputStream is, String excelName) { 53 logger.debug("发送一封带一个附件的邮件"); 54 //基础校验 55 if (StringUtils.isBlank(emailEntity.getHost())) { 56 throw new JyException("发件服务器未设置"); 57 } 58 if (emailEntity.getPort() == null) { 59 emailEntity.setPort(25); 60 } 61 if (StringUtils.isBlank(emailEntity.getFrom())) { 62 throw new JyException("发件人未设置"); 63 } 64 if (StringUtils.isBlank(emailEntity.getPassword())) { 65 throw new JyException("发件人密码未设置"); 66 } 67 68 Properties properties = new Properties(); 69 properties.setProperty(MAIL_SMTP_AUTH, "true"); 70 properties.setProperty(MAIL_TRANSPORT_PROTOCOL, "smtp"); 71 properties.setProperty(MAIL_SMTP_HOST, emailEntity.getHost()); 72 73 Session session = Session.getDefaultInstance(properties); 74 session.setDebug(false); 75 MimeMessage message = new MimeMessage(session); 76 77 try { 78 //设置发件人邮箱 79 message.setFrom(new InternetAddress(emailEntity.getFrom())); 80 setReCcList(emailEntity, message); 81 82 83 //设置主题 84 message.setSubject(emailEntity.getSubject()); 85 //设置中文 86 message.addHeader("charset", "UTF-8"); 87 88 //正文 89 Multipart multipart = new MimeMultipart(); 90 BodyPart bodyPart = new MimeBodyPart(); 91 //设置邮件正文内容 92 bodyPart.setText(emailEntity.getContent()); 93 //设置正文中文 94 bodyPart.setHeader("Content-Type", "text/html;charset=UTF-8"); 95 multipart.addBodyPart(bodyPart); 96 97 //附件 98 MimeBodyPart fileBody = new MimeBodyPart(); 99 DataSource source = new ByteArrayDataSource(is, "application/vnd.ms-excel"); 100 fileBody.setDataHandler(new DataHandler(source)); 101 String filename = StringUtils.isBlank(excelName) ? "excel" + FileUtils.EXCEL_SUFFIX : excelName; 102 103 fileBody.setFileName(MimeUtility.encodeText(filename)); 104 multipart.addBodyPart(fileBody); 105 106 message.setContent(multipart); 107 message.setSentDate(new Date()); 108 message.saveChanges(); 109 Transport transport = session.getTransport("smtp"); 110 111 transport.connect(emailEntity.getHost(), emailEntity.getPort(), emailEntity.getFrom(), emailEntity.getPassword()); 112 transport.sendMessage(message, message.getAllRecipients()); 113 transport.close(); 114 115 } catch (Exception e) { 116 e.printStackTrace(); 117 throw new JyException("邮件发送失败"); 118 } 119 } 120 121 public static void sendSslAttachMail(EmailEntity emailEntity, InputStream is, String excelName) { 122 logger.debug("发送一封带一个附件的邮件"); 123 //基础校验 124 if (StringUtils.isBlank(emailEntity.getHost())) { 125 throw new JyException("发件服务器未设置"); 126 } 127 if (emailEntity.getPort() == null) { 128 emailEntity.setPort(465); 129 } 130 if (StringUtils.isBlank(emailEntity.getFrom())) { 131 throw new JyException("发件人未设置"); 132 } 133 if (StringUtils.isBlank(emailEntity.getPassword())) { 134 throw new JyException("发件人密码未设置"); 135 } 136 137 //设置SSL连接、邮件配置 138 Security.addProvider(new Provider()); 139 Properties props = System.getProperties(); 140 props.setProperty("mail.smtp.host", emailEntity.getHost()); 141 props.setProperty("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory"); 142 props.setProperty("mail.smtp.socketFactory.fallback", "false"); 143 props.setProperty("mail.smtp.port", "465"); 144 props.setProperty("mail.smtp.socketFactory.port", "465"); 145 props.setProperty("mail.smtp.auth", "true"); 146 147 Session session = Session.getDefaultInstance(props, new Authenticator() { 148 @Override 149 protected PasswordAuthentication getPasswordAuthentication() { 150 return new PasswordAuthentication(emailEntity.getFrom(), emailEntity.getPassword()); 151 } 152 }); 153 154 session.setDebug(false); 155 MimeMessage message = new MimeMessage(session); 156 157 try { 158 //设置发件人邮箱 159 message.setFrom(new InternetAddress(emailEntity.getFrom())); 160 setReCcList(emailEntity, message); 161 162 163 //设置主题 164 message.setSubject(emailEntity.getSubject()); 165 //设置中文 166 message.addHeader("charset", "UTF-8"); 167 168 //正文 169 Multipart multipart = new MimeMultipart(); 170 BodyPart bodyPart = new MimeBodyPart(); 171 //设置邮件正文内容 172 bodyPart.setText(emailEntity.getContent()); 173 //设置正文中文 174 bodyPart.setHeader("Content-Type", "text/html;charset=UTF-8"); 175 multipart.addBodyPart(bodyPart); 176 177 //附件 178 MimeBodyPart fileBody = new MimeBodyPart(); 179 DataSource source = new ByteArrayDataSource(is, "application/vnd.ms-excel"); 180 fileBody.setDataHandler(new DataHandler(source)); 181 String filename = StringUtils.isBlank(excelName) ? "excel" + FileUtils.EXCEL_SUFFIX : excelName; 182 183 fileBody.setFileName(MimeUtility.encodeText(filename)); 184 multipart.addBodyPart(fileBody); 185 186 message.setContent(multipart); 187 message.setSentDate(new Date()); 188 message.saveChanges(); 189 Transport transport = session.getTransport("smtp"); 190 191 transport.connect(emailEntity.getHost(), emailEntity.getPort(), emailEntity.getFrom(), emailEntity.getPassword()); 192 transport.sendMessage(message, message.getAllRecipients()); 193 transport.close(); 194 195 } catch (SendFailedException se) { 196 // 判断当前失败信息,如果为地址错误,则过滤无效地址后重发 197 if (INVALID_ADDRESS_MESSAGE.equals(se.getMessage())) { 198 Address[] addresses = se.getInvalidAddresses(); 199 List<String> addressList = Lists.newArrayList(); 200 201 List<String> recipientList = emailEntity.getRecipients(); 202 List<String> ccList = emailEntity.getCcList(); 203 for (Address address : addresses) { 204 InternetAddress internetAddress = (InternetAddress) address; 205 if (recipientList.contains(internetAddress.getAddress())) { 206 recipientList.remove(internetAddress.getAddress()); 207 } 208 if (ccList.contains(internetAddress.getAddress())) { 209 ccList.remove(internetAddress.getAddress()); 210 } 211 addressList.add(internetAddress.getAddress()); 212 } 213 logger.error("存在不可用邮箱地址:{},过滤后重新发送邮件...", JSON.toJSONString(addressList)); 214 215 if (CollectionUtils.isEmpty(recipientList)) { 216 logger.error("不存在有效的邮箱地址,已配置但无效的邮箱地址:{}", JSON.toJSONString(addressList)); 217 throw new JyException("不存在有效的邮箱地址,已配置但无效的邮箱地址:" + JSON.toJSONString(addressList)); 218 } 219 // 重新发送 220 emailEntity.setRecipients(new Vector<>(recipientList)); 221 if (!CollectionUtils.isEmpty(ccList)) { 222 emailEntity.setCcList(new Vector<>(ccList)); 223 } 224 sendSslAttachMail(emailEntity, is, excelName); 225 } 226 } catch (Exception e) { 227 e.printStackTrace(); 228 throw new JyException("邮件发送失败"); 229 } 230 } 231 232 private static void setReCcList(EmailEntity emailEntity, MimeMessage message) throws MessagingException { 233 //设置收件人和抄送人 234 if (!CollectionUtils.isEmpty(emailEntity.getRecipients())) { 235 Address[] addresses = new Address[emailEntity.getRecipients().size()]; 236 for (int i = 0; i < emailEntity.getRecipients().size(); i++) { 237 addresses[i] = new InternetAddress(emailEntity.getRecipients().get(i)); 238 } 239 message.addRecipients(Message.RecipientType.TO, addresses); 240 } 241 if (!CollectionUtils.isEmpty(emailEntity.getCcList())) { 242 Address[] ccList = new Address[emailEntity.getCcList().size()]; 243 for (int i = 0; i < emailEntity.getCcList().size(); i++) { 244 ccList[i] = new InternetAddress(emailEntity.getCcList().get(i)); 245 } 246 message.addRecipients(Message.RecipientType.CC, ccList); 247 } 248 } 249 250 /** 251 * 发送带多个附件的邮件 252 * 253 * @param emailEntity 邮箱参数对象 254 * @param fileList 附件文件列表 255 */ 256 public static void sendMultiAttachEmail(EmailEntity emailEntity, List<File> fileList) { 257 logger.debug("发送多附件邮件..."); 258 //基础校验 259 if (StringUtils.isBlank(emailEntity.getHost())) { 260 throw new JyException("发件服务器未设置"); 261 } 262 if (emailEntity.getPort() == null) { 263 emailEntity.setPort(25); 264 } 265 if (StringUtils.isBlank(emailEntity.getFrom())) { 266 throw new JyException("发件人未设置"); 267 } 268 if (StringUtils.isBlank(emailEntity.getPassword())) { 269 throw new JyException("发件人密码未设置"); 270 } 271 272 Properties properties = new Properties(); 273 properties.setProperty(MAIL_SMTP_AUTH, "true"); 274 properties.setProperty(MAIL_TRANSPORT_PROTOCOL, "smtp"); 275 properties.setProperty(MAIL_SMTP_HOST, emailEntity.getHost()); 276 277 Session session = Session.getDefaultInstance(properties); 278 session.setDebug(false); 279 setEmailMessage(emailEntity, fileList, session); 280 } 281 282 private static void setEmailMessage(EmailEntity emailEntity, List<File> fileList, Session session) { 283 MimeMessage message = new MimeMessage(session); 284 285 try { 286 //设置发件人邮箱 287 message.setFrom(new InternetAddress(emailEntity.getFrom())); 288 289 //设置收件人和抄送人 290 setReCcList(emailEntity, message); 291 //设置主题 292 message.setSubject(MimeUtility.encodeText(emailEntity.getSubject(), "UTF-8", "B")); 293 //设置中文 294 message.addHeader("charset", "UTF-8"); 295 296 //正文 297 Multipart multipart = new MimeMultipart(); 298 BodyPart bodyPart = new MimeBodyPart(); 299 //设置邮件正文内容 300 bodyPart.setText(emailEntity.getContent()); 301 //设置正文中文 302 bodyPart.setHeader("Content-Type", "text/html;charset=UTF-8"); 303 multipart.addBodyPart(bodyPart); 304 305 //附件 306 307 for (File file : fileList) { 308 MimeBodyPart fileBody = new MimeBodyPart(); 309 310 FileDataSource fileDataSource = new FileDataSource(file); 311 fileBody.setDataHandler(new DataHandler(fileDataSource)); 312 fileBody.setFileName(MimeUtility.encodeText(file.getName(), "UTF-8", "B")); 313 314 multipart.addBodyPart(fileBody); 315 } 316 317 message.setContent(multipart); 318 message.setSentDate(new Date()); 319 message.saveChanges(); 320 Transport transport = session.getTransport("smtp"); 321 322 transport.connect(emailEntity.getHost(), emailEntity.getPort(), emailEntity.getFrom(), emailEntity.getPassword()); 323 transport.sendMessage(message, message.getAllRecipients()); 324 transport.close(); 325 326 } catch (SendFailedException se) { 327 // 判断当前失败信息,如果为地址错误,则过滤无效地址后重发 328 if (INVALID_ADDRESS_MESSAGE.equals(se.getMessage())) { 329 Address[] addresses = se.getInvalidAddresses(); 330 List<String> addressList = Lists.newArrayList(); 331 332 List<String> recipientList = emailEntity.getRecipients(); 333 List<String> ccList = emailEntity.getCcList(); 334 for (Address address : addresses) { 335 InternetAddress internetAddress = (InternetAddress) address; 336 if (recipientList.contains(internetAddress.getAddress())) { 337 recipientList.remove(internetAddress.getAddress()); 338 } 339 if (ccList.contains(internetAddress.getAddress())) { 340 ccList.remove(internetAddress.getAddress()); 341 } 342 addressList.add(internetAddress.getAddress()); 343 } 344 logger.error("存在不可用邮箱地址:{},过滤后重新发送邮件...", JSON.toJSONString(addressList)); 345 346 if (CollectionUtils.isEmpty(recipientList)) { 347 logger.error("不存在有效的邮箱地址,已配置但无效的邮箱地址:{}", JSON.toJSONString(addressList)); 348 throw new JyException("不存在有效的邮箱地址,已配置但无效的邮箱地址:" + JSON.toJSONString(addressList)); 349 } 350 // 重新发送 351 emailEntity.setRecipients(new Vector<>(recipientList)); 352 if (!CollectionUtils.isEmpty(ccList)) { 353 emailEntity.setCcList(new Vector<>(ccList)); 354 } 355 setEmailMessage(emailEntity, fileList, session); 356 } 357 } catch (Exception e) { 358 e.printStackTrace(); 359 throw new JyException("邮件发送失败"); 360 } 361 } 362 363 /** 364 * 发送邮件 365 * 366 * @param email 邮件发送参数 367 * @param fileList 附件列表 368 * @return 是否发送成功 369 */ 370 public static boolean sendEmail(EmailEntity email, List<File> fileList) { 371 try { 372 EmailUtils.sendMultiAttachEmail(email, fileList); 373 logger.info("邮件发送成功"); 374 return true; 375 } catch (JyException e) { 376 logger.error("邮件发送失败{}", e.getMessage()); 377 return false; 378 } 379 } 380 381 /** 382 * SSL发送邮件 465端口 383 * 384 * @param email 385 * @param fileList 386 * @return 387 */ 388 public static boolean sendSslEmail(EmailEntity email, List<File> fileList) { 389 logger.info("ssl发送邮件..."); 390 try { 391 if (email.getPort() == null) { 392 email.setPort(465); 393 } 394 //设置SSL连接、邮件配置 395 Security.addProvider(new Provider()); 396 Properties props = System.getProperties(); 397 props.setProperty("mail.smtp.host", email.getHost()); 398 props.setProperty("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory"); 399 props.setProperty("mail.smtp.socketFactory.fallback", "false"); 400 props.setProperty("mail.smtp.port", "465"); 401 props.setProperty("mail.smtp.socketFactory.port", "465"); 402 props.setProperty("mail.smtp.auth", "true"); 403 404 Session session = Session.getDefaultInstance(props, new Authenticator() { 405 @Override 406 protected PasswordAuthentication getPasswordAuthentication() { 407 return new PasswordAuthentication(email.getFrom(), email.getPassword()); 408 } 409 }); 410 session.setDebug(true); 411 setEmailMessage(email, fileList, session); 412 logger.info("邮件发送成功"); 413 return true; 414 } catch (JyException e) { 415 logger.error("邮件发送失败 - {}", e.getMessage()); 416 return false; 417 } 418 } 419 420 /** 421 * 获取当前邮箱的所有邮件 -- 暂不能包含附件 422 * 423 * @param receiveEntity 424 * @return 425 * @throws Exception 426 */ 427 public static List<EmailInfo> receiveAllEmail(ReceiveEntity receiveEntity) throws Exception { 428 logger.info("收取邮件..."); 429 Folder folder = getInBox(receiveEntity); 430 // 获得收件箱的邮件列表 431 Message[] messages = folder.getMessages(); 432 return getReceivedEmailContent(messages); 433 } 434 435 /** 436 * 获取邮件信息,仅支持纯文本邮件 437 * 438 * @param messages 439 * @return 440 * @throws MessagingException 441 * @throws IOException 442 */ 443 public static List<EmailInfo> getReceivedEmailContent(Message[] messages) throws Exception { 444 List<EmailInfo> emailInfoList = Lists.newArrayList(); 445 for (Message message : messages) { 446 emailInfoList.add(getReceivedEmailContent(message)); 447 } 448 return emailInfoList; 449 } 450 451 /** 452 * 获取邮件信息,仅支持除文本邮件 453 * 454 * @param message 455 * @return 456 * @throws Exception 457 */ 458 public static EmailInfo getReceivedEmailContent(Message message) throws Exception { 459 EmailInfo emailInfo = new EmailInfo(); 460 InternetAddress[] fromAddress = (InternetAddress[]) message.getFrom(); 461 InternetAddress[] recipientAddress = (InternetAddress[]) message.getAllRecipients(); 462 emailInfo.setFrom(fromAddress[0].getAddress()); 463 List<String> recipientList = Lists.newArrayList(); 464 for (InternetAddress recipient : recipientAddress) { 465 recipientList.add(recipient.getAddress()); 466 } 467 emailInfo.setRecipient(recipientList); 468 emailInfo.setSubject(message.getSubject()); 469 470 if (message.getContentType().contains(TEXT)) { 471 //纯文本 -- 获取html 不包含图片等其他资源 472 emailInfo.setContent((String) message.getContent()); 473 } else { 474 //签名信息中含有图片 -- 暂不处理纯文本和图片 获取html内容 475 Multipart multipart = (Multipart) message.getContent(); 476 for (int i = 0; i < multipart.getCount(); i++) { 477 BodyPart bodyPart = multipart.getBodyPart(i); 478 if (!bodyPart.getContentType().contains(TEXT)) { 479 Multipart part = (Multipart) bodyPart.getContent(); 480 for (int j = 0; j < part.getCount(); j++) { 481 BodyPart bodyPart1 = part.getBodyPart(j); 482 if (bodyPart1.getContentType().contains(TEXT_HTML)) { 483 emailInfo.setContent(bodyPart1.getContent().toString()); 484 break; 485 } 486 } 487 } else if (bodyPart.getContentType().contains(TEXT_HTML)) { 488 emailInfo.setContent(bodyPart.getContent().toString()); 489 break; 490 } 491 if (StringUtils.isNotBlank(emailInfo.getContent())) { 492 break; 493 } 494 } 495 } 496 return emailInfo; 497 } 498 499 /** 500 * 获取收件箱 501 * 502 * @param receiveEntity 503 * @return 504 * @throws Exception 505 */ 506 public static Folder getInBox(ReceiveEntity receiveEntity) throws Exception { 507 Properties props = new Properties(); 508 509 props.setProperty("mail.imap.host", receiveEntity.getHost()); 510 511 props.put("mail.smtp.auth", true); 512 props.put("mail.smtps.ssl.protocols", "TSLv1 TSLv1.1 TLSv1.2"); 513 props.put("mail.transport.protocol", "imap"); 514 props.put("mail.smtp.ssl.ciphersuites", "TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256, TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256, TLS_RSA_WITH_AES_128_CBC_SHA256, TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA256, TLS_ECDH_RSA_WITH_AES_128_CBC_SHA256, TLS_DHE_RSA_WITH_AES_128_CBC_SHA256, TLS_DHE_DSS_WITH_AES_128_CBC_SHA256, TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA, TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA, TLS_RSA_WITH_AES_128_CBC_SHA, TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA, TLS_ECDH_RSA_WITH_AES_128_CBC_SHA, TLS_DHE_RSA_WITH_AES_128_CBC_SHA, TLS_DHE_DSS_WITH_AES_128_CBC_SHA, TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256, TLS_RSA_WITH_AES_128_GCM_SHA256, TLS_ECDH_ECDSA_WITH_AES_128_GCM_SHA256, TLS_ECDH_RSA_WITH_AES_128_GCM_SHA256, TLS_DHE_RSA_WITH_AES_128_GCM_SHA256, TLS_DHE_DSS_WITH_AES_128_GCM_SHA256, TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA, TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA, SSL_RSA_WITH_3DES_EDE_CBC_SHA, TLS_ECDH_ECDSA_WITH_3DES_EDE_CBC_SHA, TLS_ECDH_RSA_WITH_3DES_EDE_CBC_SHA, SSL_DHE_RSA_WITH_3DES_EDE_CBC_SHA, SSL_DHE_DSS_WITH_3DES_EDE_CBC_SHA, TLS_EMPTY_RENEGOTIATION_INFO_SCSV, TLS_DH_anon_WITH_AES_128_GCM_SHA256, TLS_DH_anon_WITH_AES_128_CBC_SHA256, TLS_ECDH_anon_WITH_AES_128_CBC_SHA, TLS_DH_anon_WITH_AES_128_CBC_SHA, TLS_ECDH_anon_WITH_3DES_EDE_CBC_SHA, SSL_DH_anon_WITH_3DES_EDE_CBC_SHA, SSL_RSA_WITH_DES_CBC_SHA, SSL_DHE_RSA_WITH_DES_CBC_SHA, SSL_DHE_DSS_WITH_DES_CBC_SHA, SSL_DH_anon_WITH_DES_CBC_SHA, SSL_RSA_EXPORT_WITH_DES40_CBC_SHA, SSL_DHE_RSA_EXPORT_WITH_DES40_CBC_SHA, SSL_DHE_DSS_EXPORT_WITH_DES40_CBC_SHA, SSL_DH_anon_EXPORT_WITH_DES40_CBC_SHA, TLS_RSA_WITH_NULL_SHA256, TLS_ECDHE_ECDSA_WITH_NULL_SHA, TLS_ECDHE_RSA_WITH_NULL_SHA, SSL_RSA_WITH_NULL_SHA, TLS_ECDH_ECDSA_WITH_NULL_SHA, TLS_ECDH_RSA_WITH_NULL_SHA, TLS_ECDH_anon_WITH_NULL_SHA, SSL_RSA_WITH_NULL_MD5, TLS_KRB5_WITH_3DES_EDE_CBC_SHA, TLS_KRB5_WITH_3DES_EDE_CBC_MD5, TLS_KRB5_WITH_DES_CBC_SHA, TLS_KRB5_WITH_DES_CBC_MD5, TLS_KRB5_EXPORT_WITH_DES_CBC_40_SHA, TLS_KRB5_EXPORT_WITH_DES_CBC_40_MD5"); 515 516 // 创建session实例对象 517 Session session = Session.getInstance(props); 518 session.setDebug(true); 519 // 创建IMAP协议的Store对象 520 Store store = session.getStore("imap"); 521 // 连接邮件服务器 522 store.connect(receiveEntity.getReceiver(), receiveEntity.getPassword()); 523 // 获得收件箱 524 Folder folder = store.getFolder("INBOX"); 525 // 以读写模式打开收件箱 526 folder.open(Folder.READ_WRITE); 527 return folder; 528 } 529}
javamail邮件工具类(增加465端口发送,收件,无效收件人过滤)
Wesley13
2021-10-11
1136 1 0
点赞
收藏
评论区
加载中...