Author: thomas.heute(a)jboss.com
Date: 2008-11-27 14:30:30 -0500 (Thu, 27 Nov 2008)
New Revision: 12312
Modified:
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/impl/mail/MailModuleImpl.java
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/modules/MailModule.java
Log:
JBPORTAL-2251: MailModule update to support non-plaintext email
Modified:
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/impl/mail/MailModuleImpl.java
===================================================================
---
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/impl/mail/MailModuleImpl.java 2008-11-27
17:16:27 UTC (rev 12311)
+++
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/impl/mail/MailModuleImpl.java 2008-11-27
19:30:30 UTC (rev 12312)
@@ -100,6 +100,9 @@
/** A serial id used to track messages locally. */
private final SynchronizedLong currentSerialId = new SynchronizedLong(0);
+ /** Default Content Type for Mail */
+ public static final String DEFAULT_CONTENT_MIME_TYPE = "text/plain";
+
public int getSMTPConnectionTimeout()
{
return SMTPConnectionTimeout;
@@ -225,11 +228,12 @@
public void send(String from,
String to,
String subject,
- String body)
+ String body,
+ String contentType)
{
try
{
- MyMessage runnable = new MyMessage(from, to, subject, body);
+ MyMessage runnable = new MyMessage(from, to, subject, body, contentType);
log.debug("Enqueuing serialId=" + runnable.serialId);
executor.execute(runnable);
log.debug("Enqueued serialId=" + runnable.serialId);
@@ -239,6 +243,14 @@
log.debug("Interrupted during deliver attempt");
}
}
+
+ public void send(String from,
+ String to,
+ String subject,
+ String body)
+ {
+ send(from, to, subject, body, DEFAULT_CONTENT_MIME_TYPE);
+ }
protected void startService()
throws Exception
@@ -303,13 +315,23 @@
String to,
String subject,
String body)
+ {
+ return deliver(serialId, from, to, subject, body, DEFAULT_CONTENT_MIME_TYPE);
+ }
+
+ public boolean deliver(long serialId,
+ String from,
+ String to,
+ String subject,
+ String body,
+ String contentType)
{
boolean delivered = false;
try
{
if ((gateway != null) && (gateway.length() > 0))
{
- delivered = deliver(serialId, gateway, from, to, subject, body);
+ delivered = deliver(serialId, gateway, from, to, subject, body,
contentType);
}
else
{
@@ -329,7 +351,8 @@
String from,
String to,
String subject,
- String body)
+ String body,
+ String contentType)
throws AddressException,
NoSuchProviderException,
MessagingException
@@ -354,8 +377,11 @@
// Prepare message
MimeMessage message = new MimeMessage(session);
message.setFrom(new InternetAddress(from));
- message.setSubject(subject);
- message.setText(body);
+
+ // Replaced message.setText(body); for setContent(...) to allow
+ // a MIME type be set. Now MailModule can support text/html messages
+ message.setContent(body, contentType);
+ message.setSubject(subject);
message.setSentDate(new Date());
message.addRecipient(javax.mail.Message.RecipientType.TO, toAddress);
@@ -417,17 +443,21 @@
public final String subject;
public final String body;
+
+ public final String contentType;
public MyMessage(String from,
String to,
String subject,
- String body)
+ String body,
+ String contentType)
{
this.serialId = currentSerialId.increment();
this.from = from;
this.to = to;
this.subject = subject;
this.body = body;
+ this.contentType = contentType;
}
public void run()
@@ -435,7 +465,7 @@
try
{
log.debug("Dequeued serialId=" + serialId + " and delivering
it");
- boolean delivered = deliver(serialId, from, to, subject, body);
+ boolean delivered = deliver(serialId, from, to, subject, body, contentType);
log.debug(delivered + " on delivery for serialId=" + serialId);
}
catch (Throwable t)
Modified:
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/modules/MailModule.java
===================================================================
---
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/modules/MailModule.java 2008-11-27
17:16:27 UTC (rev 12311)
+++
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/modules/MailModule.java 2008-11-27
19:30:30 UTC (rev 12312)
@@ -29,6 +29,8 @@
void send(String from, String to, String subject, String body);
+ void send(String from, String to, String subject, String body, String contentType);
+
void setSMTPConnectionTimeout(int SMTPConnectionTimeout);
void setSMTPTimeout(int SMTPTimeout);