mirror of
https://gitee.com/jmix/cuba.git
synced 2024-12-04 12:17:41 +08:00
Support custom SMTP headers in Emailer #PL-4569
This commit is contained in:
parent
fa1ae02f5e
commit
5b31ae36bf
@ -131,18 +131,14 @@ public class EmailSender implements EmailSenderAPI {
|
||||
}
|
||||
}
|
||||
|
||||
private void addHeaders(SendingMessage sendingMessage, MimeMessage message) {
|
||||
private void addHeaders(SendingMessage sendingMessage, MimeMessage message) throws MessagingException {
|
||||
if (sendingMessage.getHeaders() == null)
|
||||
return ;
|
||||
String[] splitHeaders = sendingMessage.getHeaders().split(SendingMessage.SEPARATOR);
|
||||
return;
|
||||
String[] splitHeaders = sendingMessage.getHeaders().split(SendingMessage.HEADERS_SEPARATOR);
|
||||
for (String header : splitHeaders) {
|
||||
EmailHeader emailHeader = EmailHeader.parse(header);
|
||||
if (emailHeader != null) {
|
||||
try {
|
||||
message.addHeader(emailHeader.getName(), emailHeader.getValue());
|
||||
} catch (MessagingException e) {
|
||||
log.warn("Can't add email header: '" + header + "'");
|
||||
}
|
||||
message.addHeader(emailHeader.getName(), emailHeader.getValue());
|
||||
} else {
|
||||
log.warn("Can't parse email header: '" + header + "'");
|
||||
}
|
||||
|
@ -566,10 +566,10 @@ public class Emailer implements EmailerAPI {
|
||||
sendingMessage.setAttachments(Collections.<SendingAttachment>emptyList());
|
||||
}
|
||||
|
||||
if (headers != null && headers.size() > 0) {
|
||||
if (headers != null && !headers.isEmpty()) {
|
||||
StringBuilder headersLine = new StringBuilder();
|
||||
for (EmailHeader header : headers) {
|
||||
headersLine.append(header.toString()).append(SendingMessage.SEPARATOR);
|
||||
headersLine.append(header.toString()).append(SendingMessage.HEADERS_SEPARATOR);
|
||||
}
|
||||
sendingMessage.setHeaders(headersLine.toString());
|
||||
} else {
|
||||
|
@ -28,7 +28,7 @@ public class SendingMessage extends StandardEntity {
|
||||
private static final long serialVersionUID = -8156998515878702538L;
|
||||
|
||||
public static final int CAPTION_LENGTH = 500;
|
||||
public static final String SEPARATOR = "\n";
|
||||
public static final String HEADERS_SEPARATOR = "\n";
|
||||
|
||||
@Column(name = "ADDRESS_TO")
|
||||
protected String address;
|
||||
|
@ -44,6 +44,7 @@ public class EmailHeader implements Serializable {
|
||||
* @param line EmailHeader name and value separated with ":" symbol.
|
||||
* @return Instance of EmailHeader object. Returns {@code null} if string has wrong format or {@code null} value.
|
||||
*/
|
||||
@Nullable
|
||||
public static EmailHeader parse(@Nullable String line) {
|
||||
if (line == null)
|
||||
return null;
|
||||
|
Loading…
Reference in New Issue
Block a user