From cca97c9ca8011018f3c531a1d9de5fde1e367574 Mon Sep 17 00:00:00 2001 From: xiaoguangbin Date: Tue, 29 Oct 2024 16:07:40 +0800 Subject: [PATCH] =?UTF-8?q?fix=EF=BC=9A=E4=BF=AE=E6=94=B9gamma=E6=8A=A5?= =?UTF-8?q?=E5=91=8A=20#MINIMUM=20=E9=83=A8=E5=88=86=EF=BC=8Cmdc=E6=A0=87?= =?UTF-8?q?=E9=A2=98=E5=A2=9E=E5=8A=A0=E5=8D=95=E4=BD=8D=EF=BC=8Cmda?= =?UTF-8?q?=E6=B2=A1=E6=95=B0=E6=8D=AE=E5=88=99=E4=B8=8D=E6=98=BE=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/jeecg/common/util/MyMailUtil.java | 83 +++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 jeecg-boot-base-core/src/main/java/org/jeecg/common/util/MyMailUtil.java diff --git a/jeecg-boot-base-core/src/main/java/org/jeecg/common/util/MyMailUtil.java b/jeecg-boot-base-core/src/main/java/org/jeecg/common/util/MyMailUtil.java new file mode 100644 index 00000000..23d6a023 --- /dev/null +++ b/jeecg-boot-base-core/src/main/java/org/jeecg/common/util/MyMailUtil.java @@ -0,0 +1,83 @@ +package org.jeecg.common.util; + +import cn.hutool.core.util.StrUtil; + +import javax.mail.Message; +import javax.mail.MessagingException; +import javax.mail.internet.InternetAddress; +import javax.mail.internet.MimeMessage; +import java.util.Date; +import java.util.Objects; + +public class MyMailUtil { + + private Integer port; + + public MyMailUtil(Integer port){ + this.port = port; + } + + /** + * 获取邮件主题 + * @param message + * @return + */ + public static String getSubject(Message message) throws MessagingException{ + String subject = null; + try { + subject = message.getSubject(); + } catch (MessagingException e) { + try { + subject = message.getHeader("subject")[0]; + } catch (MessagingException ex) { + throw new RuntimeException(ex); + } + } + return subject; + } + + public static Date getReceivedDate(Message message) throws MessagingException{ + Date receivedDate = null; + try { + receivedDate = message.getReceivedDate(); + } catch (MessagingException e) { + try { + receivedDate = new Date(message.getHeader("Date")[0]); + } catch (MessagingException ex) { + throw new RuntimeException(ex); + } + } + return receivedDate; + } + + public static String getMessageID(Message message) throws MessagingException{ + String messageId = ""; + try { + messageId = ((MimeMessage) message).getMessageID(); + } catch (MessagingException e) { + try { + messageId = Objects.isNull(message.getHeader("Message-ID")) ? "" : message.getHeader("Message-ID")[0]; + } catch (MessagingException ex) { + throw new RuntimeException(ex); + } + } + return messageId; + } + + public static String getAddress(Message message) throws MessagingException{ + String address = ""; + try { + address = ((InternetAddress) message.getFrom()[0]).getAddress(); + } catch (MessagingException e) { + try { + String[] froms = message.getHeader("From"); + if (null != froms) { + address = StrUtil.subBetween(froms[0], "<",">"); + } + } catch (MessagingException ex) { + throw new RuntimeException(ex); + } + } + return address; + } +}