[Yanel-commits] rev 52643 - public/yanel/trunk/src/core/java/org/wyona/yanel/core/util

michi at wyona.com michi at wyona.com
Tue Aug 24 09:49:07 CEST 2010


Author: michi
Date: 2010-08-24 09:49:07 +0200 (Tue, 24 Aug 2010)
New Revision: 52643

Modified:
   public/yanel/trunk/src/core/java/org/wyona/yanel/core/util/MailUtil.java
Log:
enhanced with charset and mime sub-type

Modified: public/yanel/trunk/src/core/java/org/wyona/yanel/core/util/MailUtil.java
===================================================================
--- public/yanel/trunk/src/core/java/org/wyona/yanel/core/util/MailUtil.java	2010-08-24 07:20:02 UTC (rev 52642)
+++ public/yanel/trunk/src/core/java/org/wyona/yanel/core/util/MailUtil.java	2010-08-24 07:49:07 UTC (rev 52643)
@@ -48,9 +48,19 @@
     }
 
     /**
+     * Send e-mail with a MIME type of "text/plain" and as encoding the platform's default charset
      * @param replyTo email address (if null, then no reply-to will be set)
      */
     public static void send(String smtpHost, int smtpPort, String from, String replyTo, String to, String subject, String content) throws AddressException, MessagingException {
+        send(smtpHost, smtpPort, from, replyTo, to, subject, content, java.nio.charset.Charset.defaultCharset().name(), "plain");
+    }
+
+    /**
+     * @param replyTo email address (if null, then no reply-to will be set)
+     * @param charset Charset, e.g. utf-8
+     * @param mimeSubType Mime sub-type, e.g. "html" or "plain"
+     */
+    public static void send(String smtpHost, int smtpPort, String from, String replyTo, String to, String subject, String content, String charset, String mimeSubType) throws AddressException, MessagingException {
         // Create a mail session
         Session session = null;
         if (smtpHost != null && smtpPort >= 0) {
@@ -68,7 +78,7 @@
         }
 
         // Construct the message
-        Message msg = new MimeMessage(session);
+        MimeMessage msg = new MimeMessage(session);
         msg.setFrom(new InternetAddress(from));
         if (replyTo != null) {
             InternetAddress[] replyToAddresses = new InternetAddress[1];
@@ -77,7 +87,7 @@
         }
         msg.setRecipient(Message.RecipientType.TO, new InternetAddress(to));
         msg.setSubject(subject);
-        msg.setText(content);
+        msg.setText(content, charset, mimeSubType);
 
         // Send the message
         Transport.send(msg);



More information about the Yanel-commits mailing list