Return-Path: Delivered-To: apmail-incubator-jspwiki-dev-archive@locus.apache.org Received: (qmail 20447 invoked from network); 30 Apr 2008 15:55:55 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 30 Apr 2008 15:55:55 -0000 Received: (qmail 79415 invoked by uid 500); 30 Apr 2008 15:55:57 -0000 Delivered-To: apmail-incubator-jspwiki-dev-archive@incubator.apache.org Received: (qmail 79397 invoked by uid 500); 30 Apr 2008 15:55:57 -0000 Mailing-List: contact jspwiki-dev-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: jspwiki-dev@incubator.apache.org Delivered-To: mailing list jspwiki-dev@incubator.apache.org Received: (qmail 79386 invoked by uid 99); 30 Apr 2008 15:55:57 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 30 Apr 2008 08:55:57 -0700 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.140] (HELO brutus.apache.org) (140.211.11.140) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 30 Apr 2008 15:55:01 +0000 Received: from brutus (localhost [127.0.0.1]) by brutus.apache.org (Postfix) with ESMTP id AAAF5234C105 for ; Wed, 30 Apr 2008 08:51:58 -0700 (PDT) Message-ID: <1563792140.1209570718684.JavaMail.jira@brutus> Date: Wed, 30 Apr 2008 08:51:58 -0700 (PDT) From: "Harry Metske (JIRA)" To: jspwiki-dev@incubator.apache.org Subject: [jira] Commented: (JSPWIKI-258) Sending HTML-Mail with JSPWiki In-Reply-To: <536871963.1209565315533.JavaMail.jira@brutus> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Virus-Checked: Checked by ClamAV on apache.org [ https://issues.apache.org/jira/browse/JSPWIKI-258?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12593360#action_12593360 ] Harry Metske commented on JSPWIKI-258: -------------------------------------- Can you attach your improvements in the form of a patch file, you can find instructions at http://www.jspwiki.org/wiki/ContributingChanges. Thanks, Harry > Sending HTML-Mail with JSPWiki > ------------------------------ > > Key: JSPWIKI-258 > URL: https://issues.apache.org/jira/browse/JSPWIKI-258 > Project: JSPWiki > Issue Type: Improvement > Components: Core & storage > Affects Versions: 2.6.2 > Reporter: Holger Szillat > Priority: Minor > Fix For: 2.6.2 > > Attachments: MailUtil.java > > > Hey, while writing my own little plugin, I wanted to send HTML-mails with JSPWiki, but discovered, that this was not easily possible. So I "enhanced" the MailUtil-class with the following code: > ... > /** > * Get a Mime-message associated with the given engine's mail-session. Use this > * to create a multipart Mime-message to be sent via the Wiki. > * > * @param engine the WikiEngine for the current wiki > * @return A MimeMessage associated with the mail-session. > * @author Holger Szillat > */ > 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. > * See the top-level JavaDoc for this class for a description of > * required properties and their default values.

> *

The e-mail address used for the to parameter must be in > * RFC822 format, as described in the JavaDoc for {@link javax.mail.internet.InternetAddress} > * and more fully at > * http://www.freesoft.org/CIE/RFC/822/index.htm. > * In other words, e-mail addresses should look like this:

> *
Snoop Dog <snoop.dog@shizzle.net>
> * snoop.dog@shizzle.net
> *

Note that the first form allows a "friendly" user name to be supplied > * in addition to the actual e-mail address.

> * > * @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, as plain text > * @throws AddressException > * @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(); > Session session = getMailSession(engine); > getSenderEmailAddress(session, props); > try > { > // Create and address the message > 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(content); > if (log.isInfoEnabled()) > { > log.info("Sent e-mail to=" + to + ", subject=\"" + subject + "\", used " > + (c_useJndi ? "JNDI" : "standalone") + " mail session."); > } > } > catch (MessagingException e) > { > log.error(e); > throw e; > } > } > ... -- This message is automatically generated by JIRA. - You can reply to this email to add a comment to the issue online.