mirror of
https://gitee.com/dromara/sms4j.git
synced 2025-12-06 17:08:40 +08:00
添加功能,邮件发送可用于发送携带发送人昵称的邮件
This commit is contained in:
parent
6ef9c692b8
commit
c31d23bdbf
@ -26,6 +26,11 @@ public class MailSmtpConfig {
|
|||||||
* */
|
* */
|
||||||
private String fromAddress;
|
private String fromAddress;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 发送人昵称
|
||||||
|
* */
|
||||||
|
private String nickName;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 服务器地址
|
* 服务器地址
|
||||||
* */
|
* */
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
package org.dromara.email.core.service;
|
package org.dromara.email.core.service;
|
||||||
|
|
||||||
import cn.hutool.core.collection.CollUtil;
|
import cn.hutool.core.collection.CollUtil;
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import org.dromara.email.api.Blacklist;
|
import org.dromara.email.api.Blacklist;
|
||||||
import org.dromara.email.api.MailClient;
|
import org.dromara.email.api.MailClient;
|
||||||
@ -15,6 +16,7 @@ import javax.mail.Session;
|
|||||||
import javax.mail.internet.AddressException;
|
import javax.mail.internet.AddressException;
|
||||||
import javax.mail.internet.InternetAddress;
|
import javax.mail.internet.InternetAddress;
|
||||||
import javax.mail.internet.MimeMessage;
|
import javax.mail.internet.MimeMessage;
|
||||||
|
import java.io.UnsupportedEncodingException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
@ -49,7 +51,15 @@ public class MailBuild {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
this.message = new MimeMessage(session);
|
this.message = new MimeMessage(session);
|
||||||
this.message.setFrom(new InternetAddress(config.getFromAddress()));
|
try {
|
||||||
|
if (StrUtil.isEmpty(config.getNickName())){
|
||||||
|
this.message.setFrom(new InternetAddress(config.getFromAddress()));
|
||||||
|
}else {
|
||||||
|
this.message.setFrom(new InternetAddress(config.getFromAddress(),config.getNickName()));
|
||||||
|
}
|
||||||
|
} catch (UnsupportedEncodingException e) {
|
||||||
|
throw new MailException(e);
|
||||||
|
}
|
||||||
this.config = config;
|
this.config = config;
|
||||||
this.retryInterval = config.getRetryInterval();
|
this.retryInterval = config.getRetryInterval();
|
||||||
this.maxRetries = config.getMaxRetries();
|
this.maxRetries = config.getMaxRetries();
|
||||||
@ -70,7 +80,15 @@ public class MailBuild {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
this.message = new MimeMessage(session);
|
this.message = new MimeMessage(session);
|
||||||
this.message.setFrom(new InternetAddress(config.getFromAddress()));
|
try {
|
||||||
|
if (StrUtil.isEmpty(config.getNickName())){
|
||||||
|
this.message.setFrom(new InternetAddress(config.getFromAddress()));
|
||||||
|
}else {
|
||||||
|
this.message.setFrom(new InternetAddress(config.getFromAddress(),config.getNickName()));
|
||||||
|
}
|
||||||
|
} catch (UnsupportedEncodingException e) {
|
||||||
|
throw new MailException(e);
|
||||||
|
}
|
||||||
this.config = config;
|
this.config = config;
|
||||||
this.blacklist = blacklist;
|
this.blacklist = blacklist;
|
||||||
this.retryInterval = config.getRetryInterval();
|
this.retryInterval = config.getRetryInterval();
|
||||||
@ -96,7 +114,8 @@ public class MailBuild {
|
|||||||
if (Objects.isNull(blacklist)) {
|
if (Objects.isNull(blacklist)) {
|
||||||
return InternetAddress.parse(Objects.requireNonNull(CollUtil.join(source, ",")));
|
return InternetAddress.parse(Objects.requireNonNull(CollUtil.join(source, ",")));
|
||||||
}
|
}
|
||||||
for (String s : blacklist.getBlacklist()) {
|
List<String> blacklist1 = blacklist.getBlacklist();
|
||||||
|
for (String s : blacklist1) {
|
||||||
if (!source.contains(s)) {
|
if (!source.contains(s)) {
|
||||||
list.add(s);
|
list.add(s);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -26,6 +26,11 @@ public class MailSmtpConfig {
|
|||||||
* */
|
* */
|
||||||
private String fromAddress;
|
private String fromAddress;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 发送人昵称
|
||||||
|
* */
|
||||||
|
private String nickName;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 服务器地址
|
* 服务器地址
|
||||||
* */
|
* */
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
package org.dromara.email.jakarta.core.service;
|
package org.dromara.email.jakarta.core.service;
|
||||||
|
|
||||||
import cn.hutool.core.collection.CollUtil;
|
import cn.hutool.core.collection.CollUtil;
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
import jakarta.mail.Authenticator;
|
import jakarta.mail.Authenticator;
|
||||||
import jakarta.mail.Message;
|
import jakarta.mail.Message;
|
||||||
import jakarta.mail.MessagingException;
|
import jakarta.mail.MessagingException;
|
||||||
@ -15,6 +16,7 @@ import org.dromara.email.jakarta.api.MailClient;
|
|||||||
import org.dromara.email.jakarta.comm.config.MailSmtpConfig;
|
import org.dromara.email.jakarta.comm.config.MailSmtpConfig;
|
||||||
import org.dromara.email.jakarta.comm.errors.MailException;
|
import org.dromara.email.jakarta.comm.errors.MailException;
|
||||||
|
|
||||||
|
import java.io.UnsupportedEncodingException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
@ -49,7 +51,15 @@ public class MailBuild {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
this.message = new MimeMessage(session);
|
this.message = new MimeMessage(session);
|
||||||
this.message.setFrom(new InternetAddress(config.getFromAddress()));
|
try {
|
||||||
|
if (StrUtil.isEmpty(config.getNickName())){
|
||||||
|
this.message.setFrom(new InternetAddress(config.getFromAddress()));
|
||||||
|
}else {
|
||||||
|
this.message.setFrom(new InternetAddress(config.getFromAddress(),config.getNickName()));
|
||||||
|
}
|
||||||
|
} catch (UnsupportedEncodingException e) {
|
||||||
|
throw new MailException(e);
|
||||||
|
}
|
||||||
this.config = config;
|
this.config = config;
|
||||||
this.retryInterval = config.getRetryInterval();
|
this.retryInterval = config.getRetryInterval();
|
||||||
this.maxRetries = config.getMaxRetries();
|
this.maxRetries = config.getMaxRetries();
|
||||||
@ -70,7 +80,15 @@ public class MailBuild {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
this.message = new MimeMessage(session);
|
this.message = new MimeMessage(session);
|
||||||
this.message.setFrom(new InternetAddress(config.getFromAddress()));
|
try {
|
||||||
|
if (StrUtil.isEmpty(config.getNickName())){
|
||||||
|
this.message.setFrom(new InternetAddress(config.getFromAddress()));
|
||||||
|
}else {
|
||||||
|
this.message.setFrom(new InternetAddress(config.getFromAddress(),config.getNickName()));
|
||||||
|
}
|
||||||
|
} catch (UnsupportedEncodingException e) {
|
||||||
|
throw new MailException(e);
|
||||||
|
}
|
||||||
this.config = config;
|
this.config = config;
|
||||||
this.blacklist = blacklist;
|
this.blacklist = blacklist;
|
||||||
this.retryInterval = config.getRetryInterval();
|
this.retryInterval = config.getRetryInterval();
|
||||||
@ -96,7 +114,8 @@ public class MailBuild {
|
|||||||
if (Objects.isNull(blacklist)) {
|
if (Objects.isNull(blacklist)) {
|
||||||
return InternetAddress.parse(Objects.requireNonNull(CollUtil.join(source, ",")));
|
return InternetAddress.parse(Objects.requireNonNull(CollUtil.join(source, ",")));
|
||||||
}
|
}
|
||||||
for (String s : blacklist.getBlacklist()) {
|
List<String> blacklist1 = blacklist.getBlacklist();
|
||||||
|
for (String s : blacklist1) {
|
||||||
if (!source.contains(s)) {
|
if (!source.contains(s)) {
|
||||||
list.add(s);
|
list.add(s);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user