IDEMPIERE-2104 restrict sending EMails to one single to address
This commit is contained in:
parent
7d028de0a3
commit
bbd6556f45
|
@ -42,9 +42,9 @@ public class MSysConfig extends X_AD_SysConfig
|
|||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = -4635791167798916808L;
|
||||
private static final long serialVersionUID = 8682693142401650434L;
|
||||
|
||||
public static final String ADDRESS_SAVE_REQUEST_RESPONSE_LOG = "ADDRESS_SAVE_REQUEST_RESPONSE_LOG";
|
||||
public static final String ADDRESS_SAVE_REQUEST_RESPONSE_LOG = "ADDRESS_SAVE_REQUEST_RESPONSE_LOG";
|
||||
public static final String ADDRESS_VALIDATION = "ADDRESS_VALIDATION";
|
||||
public static final String ALERT_SEND_ATTACHMENT_AS_XLS = "ALERT_SEND_ATTACHMENT_AS_XLS";
|
||||
public static final String ALLOW_APPLY_PAYMENT_TO_CREDITMEMO = "ALLOW_APPLY_PAYMENT_TO_CREDITMEMO";
|
||||
|
@ -79,6 +79,7 @@ public class MSysConfig extends X_AD_SysConfig
|
|||
public static final String LOCATION_MAX_CITY_ROWS = "LOCATION_MAX_CITY_ROWS";
|
||||
public static final String LOGIN_HELP_URL = "LOGIN_HELP_URL";
|
||||
public static final String LOGIN_SHOW_RESETPASSWORD = "LOGIN_SHOW_RESETPASSWORD";
|
||||
public static final String MAIL_DONT_SEND_TO_ADDRESS = "MAIL_DONT_SEND_TO_ADDRESS";
|
||||
public static final String MAIL_SEND_BCC_TO_ADDRESS = "MAIL_SEND_BCC_TO_ADDRESS";
|
||||
public static final String MAIL_SEND_BCC_TO_FROM = "MAIL_SEND_BCC_TO_FROM";
|
||||
public static final String MAIL_SEND_CREDENTIALS = "MAIL_SEND_CREDENTIALS";
|
||||
|
|
|
@ -155,7 +155,7 @@ public final class EMail implements Serializable
|
|||
setSmtpHost(smtpHost);
|
||||
setFrom(from);
|
||||
String bccAddressForAllMails = MSysConfig.getValue(MSysConfig.MAIL_SEND_BCC_TO_ADDRESS, Env.getAD_Client_ID(Env.getCtx()));
|
||||
if (bccAddressForAllMails != null && bccAddressForAllMails.length() > 0)
|
||||
if (! Util.isEmpty(bccAddressForAllMails, true))
|
||||
addBcc(bccAddressForAllMails);
|
||||
addTo(to);
|
||||
m_ctx = ctx;
|
||||
|
@ -291,17 +291,37 @@ public final class EMail implements Serializable
|
|||
m_msg = new SMTPMessage(session);
|
||||
// Addresses
|
||||
m_msg.setFrom(m_from);
|
||||
InternetAddress[] rec = getTos();
|
||||
if (rec.length == 1)
|
||||
m_msg.setRecipient (Message.RecipientType.TO, rec[0]);
|
||||
else
|
||||
m_msg.setRecipients (Message.RecipientType.TO, rec);
|
||||
rec = getCcs();
|
||||
if (rec != null && rec.length > 0)
|
||||
m_msg.setRecipients (Message.RecipientType.CC, rec);
|
||||
rec = getBccs();
|
||||
if (rec != null && rec.length > 0)
|
||||
m_msg.setRecipients (Message.RecipientType.BCC, rec);
|
||||
|
||||
// IDEMPIERE-2104 - intended for test or dev systems to not send undesired emails
|
||||
boolean isDontSendToAddress = MSysConfig.getBooleanValue(MSysConfig.MAIL_DONT_SEND_TO_ADDRESS, false, Env.getAD_Client_ID(Env.getCtx()));
|
||||
|
||||
if (! isDontSendToAddress) {
|
||||
InternetAddress[] rec = getTos();
|
||||
if (rec.length == 1)
|
||||
m_msg.setRecipient (Message.RecipientType.TO, rec[0]);
|
||||
else
|
||||
m_msg.setRecipients (Message.RecipientType.TO, rec);
|
||||
rec = getCcs();
|
||||
if (rec != null && rec.length > 0)
|
||||
m_msg.setRecipients (Message.RecipientType.CC, rec);
|
||||
rec = getBccs();
|
||||
if (rec != null && rec.length > 0)
|
||||
m_msg.setRecipients (Message.RecipientType.BCC, rec);
|
||||
} else {
|
||||
String bccAddressForAllMails = MSysConfig.getValue(MSysConfig.MAIL_SEND_BCC_TO_ADDRESS, Env.getAD_Client_ID(Env.getCtx()));
|
||||
if (! Util.isEmpty(bccAddressForAllMails, true)) {
|
||||
m_msg.setRecipient (Message.RecipientType.TO, new InternetAddress(bccAddressForAllMails, true));
|
||||
}
|
||||
InternetAddress[] rec = getTos();
|
||||
if (rec != null && rec.length > 0)
|
||||
m_msg.setHeader("OriginalTo", getCommaSeparatedString(rec));
|
||||
rec = getCcs();
|
||||
if (rec != null && rec.length > 0)
|
||||
m_msg.setHeader("OriginalCC", getCommaSeparatedString(rec));
|
||||
rec = getBccs();
|
||||
if (rec != null && rec.length > 0)
|
||||
m_msg.setHeader("OriginalBCC", getCommaSeparatedString(rec));
|
||||
}
|
||||
if (m_replyTo != null)
|
||||
m_msg.setReplyTo(new Address[] {m_replyTo});
|
||||
//
|
||||
|
@ -436,6 +456,16 @@ public final class EMail implements Serializable
|
|||
return m_sentMsg;
|
||||
} // send
|
||||
|
||||
private String getCommaSeparatedString(InternetAddress[] recs) {
|
||||
StringBuilder retValue = new StringBuilder();
|
||||
for (InternetAddress rec : recs) {
|
||||
if (retValue.length() > 0)
|
||||
retValue.append(",");
|
||||
retValue.append(rec.getAddress());
|
||||
}
|
||||
return retValue.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Send Result Msg
|
||||
* @return msg
|
||||
|
|
Loading…
Reference in New Issue