import java.text.MessageFormat;
import java.util.Date;
import java.util.Properties;
-import javax.mail.Address;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.Transport;
* <p>
* @param emailAddress Email address for recipient
* @param subjectLine Subject line
- * @param body Body part
+ * @param writer Body part
* @param mailSession Corresponding mail session to use
* <p>
* @throws MessagingException If something happened on message delivery
*/
- private void sendMail (final Address emailAddress, final String subjectLine, final String body, final Session mailSession) throws MessagingException {
+ private void sendMail (final WrapableEmailDelivery emailWrapper, final StringWriter writer, final Session mailSession) throws MessagingException {
// Trace message
- this.getLoggerBeanLocal().logTrace(MessageFormat.format("sendMail: emailAddress={0},subjectLine={1},body={2},mailSession={3} - CALLED!", emailAddress, subjectLine, body, mailSession)); //NOI18N
+ this.getLoggerBeanLocal().logTrace(MessageFormat.format("sendMail: emailWrapper={0},body={1},mailSession={2} - CALLED!", emailWrapper, writer, mailSession)); //NOI18N
// Are the additional properties set?
if (null == this.properties) {
MimeMessage message = new MimeMessage(mailSession);
// Set subject, recipients and body
- message.setSubject(subjectLine);
- message.setRecipients(javax.mail.Message.RecipientType.TO, InternetAddress.parse(emailAddress.toString(), true));
+ message.setSubject(emailWrapper.getSubjectLine());
+ message.setRecipients(javax.mail.Message.RecipientType.TO, InternetAddress.parse(emailWrapper.getRecipient().toString(), true));
message.setSentDate(new Date());
- message.setText(body);
+ message.setText(writer.toString());
message.setHeader("MIME-Version", "1.0"); //NOI18N
message.setHeader("Content-Type", "text/plain; charset=UTF-8"); //NOI18N
message.setHeader("Content-Transfer-Encoding", "8bit"); //NOI18N
// Directly send email
Transport.send(message);
+
+ // Trace message
+ this.getLoggerBeanLocal().logTrace("init: EXIT!"); //NOI18N
}
/**
template.merge(context, writer);
// Get all out and send it
- this.sendMail(emailWrapper.getRecipient(), emailWrapper.getSubjectLine(), writer.toString(), mailSession);
+ this.sendMail(emailWrapper, writer, mailSession);
+
+ // Trace message
+ this.getLoggerBeanLocal().logTrace("init: EXIT!"); //NOI18N
}
}