|
@@ -43,7 +43,13 @@ public class SendMailUtil {
|
|
|
MimeMessage message = new MimeMessage(session);
|
|
|
message.setSubject(mailDto.getMailTitle());
|
|
|
message.setFrom(new InternetAddress(mailDto.getMailFrom()));
|
|
|
- message.setRecipient(MimeMessage.RecipientType.TO, new InternetAddress(mailDto.getMailTo().trim()));
|
|
|
+ insertRecipient(message, MimeMessage.RecipientType.TO, mailDto.getMailFrom());
|
|
|
+ if (StringUtils.hasText(mailDto.getMailCc())) {
|
|
|
+ insertRecipient(message, MimeMessage.RecipientType.CC, mailDto.getMailCc());
|
|
|
+ }
|
|
|
+ if (StringUtils.hasText(mailDto.getMailBcc())) {
|
|
|
+ insertRecipient(message, MimeMessage.RecipientType.BCC, mailDto.getMailBcc());
|
|
|
+ }
|
|
|
Multipart multipart = new MimeMultipart();
|
|
|
// 添加邮件正文
|
|
|
MimeBodyPart textPart = new MimeBodyPart();
|
|
@@ -59,6 +65,13 @@ public class SendMailUtil {
|
|
|
return message;
|
|
|
}
|
|
|
|
|
|
+ private static void insertRecipient(MimeMessage message, Message.RecipientType recipientType, String mailPath) throws MessagingException{
|
|
|
+ String[] email = mailPath.split(";");
|
|
|
+ for (String mail : email) {
|
|
|
+ message.setRecipient(recipientType, new InternetAddress(mail.trim()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 创建附件 BodyPart
|
|
|
*/
|
|
@@ -115,6 +128,9 @@ public class SendMailUtil {
|
|
|
* 发送带附件的 HTML 邮件
|
|
|
*/
|
|
|
public static void sendHtmlFileMail(MailDto mailDto) {
|
|
|
+ if (!StringUtils.hasText(mailDto.getMailTo())) {
|
|
|
+ throw new RuntimeException("收件人不能为空");
|
|
|
+ }
|
|
|
if (CollectionUtils.isEmpty(mailDto.getMailFilePath())) {
|
|
|
throw new RuntimeException("邮件附件为空");
|
|
|
}
|