[Yanel-commits] rev 53151 -
public/yanel/trunk/src/core/java/org/wyona/yanel/core/util
michi at wyona.com
michi at wyona.com
Sun Sep 12 13:38:36 CEST 2010
Author: michi
Date: 2010-09-12 13:38:35 +0200 (Sun, 12 Sep 2010)
New Revision: 53151
Modified:
public/yanel/trunk/src/core/java/org/wyona/yanel/core/util/MailUtil.java
Log:
from (sender) name introduced
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-09-12 10:18:03 UTC (rev 53150)
+++ public/yanel/trunk/src/core/java/org/wyona/yanel/core/util/MailUtil.java 2010-09-12 11:38:35 UTC (rev 53151)
@@ -41,6 +41,18 @@
}
/**
+ * @param fromAddress From address, e.g. contact at wyona.org
+ * @param fromName From name, e.g. Wyona
+ * @param replyTo email address (if null, then no reply-to will be set)
+ * @param to To address
+ * @param subject Subject of email
+ * @param content Body of email
+ */
+ public static void send(String fromAddress, String fromName, String replyTo, String to, String subject, String content) throws AddressException, MessagingException {
+ send(null, -1, fromAddress, fromName, replyTo, to, subject, content, java.nio.charset.Charset.defaultCharset().name(), "plain");
+ }
+
+ /**
* Send an email without a reply-to address
*/
public static void send(String smtpHost, int smtpPort, String from, String to, String subject, String content) throws AddressException, MessagingException {
@@ -57,11 +69,21 @@
}
/**
+ * @deprecated
+ */
+ 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 {
+ String fromName = null;
+ send(smtpHost, smtpPort, from, fromName, replyTo, to, subject, content, charset, mimeSubType);
+ }
+
+ /**
* @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"
+ * @param fromEmailAdress E-Mail address of sender, e.g. contact at wyona.org
+ * @param fromName Name of sender, e.g. Wyona
*/
- 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 {
+ public static void send(String smtpHost, int smtpPort, String fromEmailAddress, String fromName, 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) {
@@ -91,7 +113,16 @@
// Construct the message
MimeMessage msg = new MimeMessage(session);
- msg.setFrom(new InternetAddress(from));
+ if (fromName != null && fromName. length() > 0) {
+ try {
+ msg.setFrom(new InternetAddress(fromEmailAddress, fromName));
+ } catch (java.io.UnsupportedEncodingException e) {
+ log.error(e, e);
+ msg.setFrom(new InternetAddress(fromEmailAddress));
+ }
+ } else {
+ msg.setFrom(new InternetAddress(fromEmailAddress));
+ }
if (replyTo != null) {
InternetAddress[] replyToAddresses = new InternetAddress[1];
replyToAddresses[0] = new InternetAddress(replyTo);
More information about the Yanel-commits
mailing list