Index: src/com/ecyrd/jspwiki/util/MailUtil.java =================================================================== --- src/com/ecyrd/jspwiki/util/MailUtil.java (Revision 653333) +++ src/com/ecyrd/jspwiki/util/MailUtil.java (Arbeitskopie) @@ -26,6 +26,7 @@ import javax.mail.internet.AddressException; import javax.mail.internet.InternetAddress; import javax.mail.internet.MimeMessage; +import javax.mail.internet.MimeMultipart; import javax.naming.Context; import javax.naming.InitialContext; import javax.naming.NamingException; @@ -189,6 +190,7 @@ * @author Christoph Sauer * @author Dan Frankowski * @author Andrew Jaquith + * @author Holger Szillat */ public final class MailUtil { @@ -245,6 +247,20 @@ } /** + * Get a Mime-message associated with the given engine's mail-session. Use this + * to create a multipart Mime-message to be sent via JSPWiki. + * + * @param engine the WikiEngine for the current wiki + * @return A MimeMessage associated with the mail-session. + */ + public static MimeMessage getMimeMessage(WikiEngine engine) { + Session session = getMailSession(engine); + MimeMessage msg = new MimeMessage(session); + + return msg; + } + + /** *
Sends an e-mail to a specified receiver using a JavaMail Session supplied
* by a JNDI mail session factory (preferred) or a locally initialized
* session based on properties in jspwiki.properties.
@@ -268,6 +284,35 @@
* @throws MessagingException
*/
public static void sendMessage(WikiEngine engine, String to, String subject, String content)
+ throws AddressException, MessagingException {
+ Session session = getMailSession(engine);
+
+ MimeMessage msg = getMimeMessage(engine);
+ msg.setText(content, "UTF-8");
+
+ sendMessage(engine, to, subject, msg);
+ }
+
+ /**
+ *
Sends an e-mail to a specified receiver using a JavaMail Session supplied
+ * by a JNDI mail session factory (preferred) or a locally initialized
+ * session based on properties in jspwiki.properties.
+ * See the top-level JavaDoc for this class for a description of
+ * required properties and their default values.
This method should be used to send a Mime-multipart message using the Wiki's + * Mail-session. + *
+ * + * @param engine the WikiEngine for the current wiki + * @param to the receiver + * @param subject the subject line of the message + * @param content the contents of the mail message + * @throws AddressException + * @throws MessagingException + * + * @author Holger Szillat + */ + public static void sendMessage(WikiEngine engine, String to, String subject, Message content) throws AddressException, MessagingException { Properties props = engine.getWikiProperties(); @@ -277,15 +322,13 @@ try { // Create and address the message - MimeMessage msg = new MimeMessage(session); - msg.setFrom(new InternetAddress(fromAddress)); - msg.setRecipients(Message.RecipientType.TO, InternetAddress.parse(to, false)); - msg.setSubject(subject); - msg.setText(content, "UTF-8"); - msg.setSentDate(new Date()); + content.setFrom(new InternetAddress(fromAddress)); + content.setRecipients(Message.RecipientType.TO, InternetAddress.parse(to, false)); + content.setSubject(subject); + content.setSentDate(new Date()); // Send and log it - Transport.send(msg); + Transport.send(content); if (log.isInfoEnabled()) { log.info("Sent e-mail to=" + to + ", subject=\"" + subject + "\", used "