Skip to content

Commit

Permalink
0004250: MailService: Allow the specification of TO, CC, and BCC
Browse files Browse the repository at this point in the history
recipients in the MailService service
  • Loading branch information
philipmarzullo64 committed Jan 17, 2020
1 parent 718ec9b commit b3d5282
Showing 1 changed file with 25 additions and 7 deletions.
Expand Up @@ -33,6 +33,7 @@
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;

import org.apache.commons.lang.StringUtils;
import org.jumpmind.properties.TypedProperties;
import org.jumpmind.symmetric.common.ParameterConstants;
import org.jumpmind.symmetric.db.ISymmetricDialect;
Expand All @@ -55,23 +56,32 @@ public MailService(IParameterService parameterService, ISymmetricDialect symmetr
super(parameterService, symmetricDialect);
}

public String sendEmail(String subject, String text, String recipients) {
return sendEmail(subject, text, recipients, getJavaMailProperties(),
public String sendEmail(String subject, String text, String toRecipients) {
return sendEmail(subject, text, toRecipients, null, null);
}

public String sendEmail(String subject, String text, String toRecipients, String ccRecipients, String bccRecipients) {
return sendEmail(subject, text, toRecipients, ccRecipients, bccRecipients, getJavaMailProperties(),
parameterService.getString(ParameterConstants.SMTP_TRANSPORT, "smtp"),
parameterService.is(ParameterConstants.SMTP_USE_AUTH, false),
parameterService.getString(ParameterConstants.SMTP_USER),
parameterService.getString(ParameterConstants.SMTP_PASSWORD));
}

public String sendEmail(String subject, String text, String recipients, TypedProperties prop) {
return sendEmail(subject, text, recipients, getJavaMailProperties(prop),
public String sendEmail(String subject, String text, String toRecipients, TypedProperties prop) {
return sendEmail(subject, text, toRecipients, null, null, prop);
}

public String sendEmail(String subject, String text, String toRecipients, String ccRecipients, String bccRecipients, TypedProperties prop) {
return sendEmail(subject, text, toRecipients, ccRecipients, bccRecipients, getJavaMailProperties(prop),
prop.get(ParameterConstants.SMTP_TRANSPORT, "smtp"),
prop.is(ParameterConstants.SMTP_USE_AUTH, false),
prop.get(ParameterConstants.SMTP_USER), prop.get(ParameterConstants.SMTP_PASSWORD));
}

protected String sendEmail(String subject, String text, String recipients, Properties prop,
String transportType, boolean useAuth, String user, String password) {
protected String sendEmail(String subject, String text, String toRecipients, String ccRecipients, String bccRecipients,
Properties prop, String transportType, boolean useAuth, String user, String password)
{
Session session = Session.getInstance(prop);
ByteArrayOutputStream ba = null;
if (log.isDebugEnabled()) {
Expand Down Expand Up @@ -102,7 +112,15 @@ protected String sendEmail(String subject, String text, String recipients, Prope
try {
MimeMessage message = new MimeMessage(session);
message.setSentDate(new Date());
message.setRecipients(RecipientType.TO, recipients);
if(StringUtils.isNotEmpty(toRecipients)) {
message.setRecipients(RecipientType.TO, toRecipients);
}
if(StringUtils.isNotEmpty(ccRecipients)) {
message.setRecipients(RecipientType.CC, ccRecipients);
}
if(StringUtils.isNotEmpty(bccRecipients)) {
message.setRecipients(RecipientType.BCC, bccRecipients);
}
message.setSubject(subject);
message.setText(text);
message.setFrom(new InternetAddress(prop.getProperty(JAVAMAIL_FROM)));
Expand Down

0 comments on commit b3d5282

Please sign in to comment.