Author: epugh
Date: Wed Aug 24 14:10:01 2005
New Revision: 239928
URL: http://svn.apache.org/viewcvs?rev=239928&view=rev
Log:
Bug 3588 Allow access to MimeMessage from Email class
Modified:
jakarta/commons/proper/email/trunk/src/java/org/apache/commons/mail/Email.java
jakarta/commons/proper/email/trunk/src/java/org/apache/commons/mail/HtmlEmail.java
jakarta/commons/proper/email/trunk/src/java/org/apache/commons/mail/MultiPartEmail.java
jakarta/commons/proper/email/trunk/xdocs/changes.xml
Modified:
jakarta/commons/proper/email/trunk/src/java/org/apache/commons/mail/Email.java
URL:
http://svn.apache.org/viewcvs/jakarta/commons/proper/email/trunk/src/java/org/apache/commons/mail/Email.java?rev=239928&r1=239927&r2=239928&view=diff
==============================================================================
---
jakarta/commons/proper/email/trunk/src/java/org/apache/commons/mail/Email.java
(original)
+++
jakarta/commons/proper/email/trunk/src/java/org/apache/commons/mail/Email.java
Wed Aug 24 14:10:01 2005
@@ -35,6 +35,7 @@
import javax.mail.internet.MimeMultipart;
import org.apache.commons.lang.StringUtils;
+import org.apache.commons.lang.Validate;
/**
* The base class for all email messages. This class sets the
@@ -350,7 +351,7 @@
* @throws EmailException thrown when host name was not set.
* @since 1.0
*/
- protected Session getMailSession() throws EmailException
+ public Session getMailSession() throws EmailException
{
if (this.session == null)
{
@@ -735,12 +736,12 @@
public abstract Email setMsg(String msg) throws EmailException;
/**
- * Does the work of actually sending the email.
+ * Build the internal MimeMessage to be sent.
*
* @throws EmailException if there was an error.
* @since 1.0
*/
- public void send() throws EmailException
+ public void buildMimeMessage() throws EmailException
{
try
{
@@ -839,8 +840,6 @@
Store store = session.getStore("pop3");
store.connect(this.popHost, this.popUsername,
this.popPassword);
}
-
- Transport.send(this.message);
}
catch (MessagingException me)
{
@@ -849,6 +848,57 @@
}
/**
+ * Sends the previously created MimeMessage to the SMTP server.
+ *
+ * @return the message id of the underlying MimeMessage
+ * @throws EmailException the sending failed
+ */
+ public String sendMimeMessage()
+ throws EmailException
+ {
+ Validate.notNull(this.message,"message");
+
+ try
+ {
+ Transport.send(this.message);
+ return this.message.getMessageID();
+ }
+ catch (Throwable t)
+ {
+ String msg = "Sending the email to the following server failed : "
+ + this.getHostName()
+ + ":"
+ + this.getSmtpPort();
+
+ throw new EmailException(msg,t);
+ }
+ }
+
+ /**
+ * Returns the internal MimeMessage. Please not that the
+ * MimeMessage is build by the buildMimeMessage() method.
+ *
+ * @return the MimeMessage
+ */
+ public MimeMessage getMimeMessage()
+ {
+ return this.message;
+ }
+
+ /**
+ * Sends the email. Internally we build a MimeMessage
+ * which is afterwards sent to the SMTP server.
+ *
+ * @return the message id of the underlying MimeMessage
+ * @throws EmailException the sending failed
+ */
+ public String send() throws EmailException
+ {
+ this.buildMimeMessage();
+ return this.sendMimeMessage();
+ }
+
+ /**
* Sets the sent date for the email. The sent date will default to the
* current date if not explictly set.
*
@@ -874,7 +924,47 @@
}
return this.sentDate;
}
-
+
+ /**
+ * Gets the subject of the email.
+ *
+ * @return email subject
+ */
+ public String getSubject()
+ {
+ return this.subject;
+ }
+
+ /**
+ * Gets the sender of the email.
+ *
+ * @return from address
+ */
+ public InternetAddress getFromAddress()
+ {
+ return this.fromAddress;
+ }
+
+ /**
+ * Gets the host name of the SMTP server,
+ *
+ * @return host name
+ */
+ public String getHostName()
+ {
+ return this.hostName;
+ }
+
+ /**
+ * Gets the listening port of the SMTP server.
+ *
+ * @return smtp port
+ */
+ public String getSmtpPort()
+ {
+ return this.smtpPort;
+ }
+
/**
* Utility to copy List of known InternetAddress objects into an
* array.
Modified:
jakarta/commons/proper/email/trunk/src/java/org/apache/commons/mail/HtmlEmail.java
URL:
http://svn.apache.org/viewcvs/jakarta/commons/proper/email/trunk/src/java/org/apache/commons/mail/HtmlEmail.java?rev=239928&r1=239927&r2=239928&view=diff
==============================================================================
---
jakarta/commons/proper/email/trunk/src/java/org/apache/commons/mail/HtmlEmail.java
(original)
+++
jakarta/commons/proper/email/trunk/src/java/org/apache/commons/mail/HtmlEmail.java
Wed Aug 24 14:10:01 2005
@@ -204,12 +204,12 @@
}
/**
- * Does the work of actually sending the email.
+ * Does the work of actually building the email.
*
* @exception EmailException if there was an error.
* @since 1.0
*/
- public void send() throws EmailException
+ public void buildMimeMessage() throws EmailException
{
try
{
@@ -229,7 +229,7 @@
{
throw new EmailException(me);
}
- super.send();
+ super.buildMimeMessage();
}
/**
Modified:
jakarta/commons/proper/email/trunk/src/java/org/apache/commons/mail/MultiPartEmail.java
URL:
http://svn.apache.org/viewcvs/jakarta/commons/proper/email/trunk/src/java/org/apache/commons/mail/MultiPartEmail.java?rev=239928&r1=239927&r2=239928&view=diff
==============================================================================
---
jakarta/commons/proper/email/trunk/src/java/org/apache/commons/mail/MultiPartEmail.java
(original)
+++
jakarta/commons/proper/email/trunk/src/java/org/apache/commons/mail/MultiPartEmail.java
Wed Aug 24 14:10:01 2005
@@ -211,13 +211,13 @@
}
/**
- * Sends the mail message
+ * Builds the actual MimeMessage
*
* @throws EmailException see javax.mail.internet.MimeBodyPart
* for definitions
* @since 1.0
*/
- public void send() throws EmailException
+ public void buildMimeMessage() throws EmailException
{
try
{
@@ -244,7 +244,7 @@
getContainer().setSubType(subType);
}
- super.send();
+ super.buildMimeMessage();
}
catch (MessagingException me)
{
Modified: jakarta/commons/proper/email/trunk/xdocs/changes.xml
URL:
http://svn.apache.org/viewcvs/jakarta/commons/proper/email/trunk/xdocs/changes.xml?rev=239928&r1=239927&r2=239928&view=diff
==============================================================================
--- jakarta/commons/proper/email/trunk/xdocs/changes.xml (original)
+++ jakarta/commons/proper/email/trunk/xdocs/changes.xml Wed Aug 24 14:10:01
2005
@@ -22,6 +22,9 @@
<body>
<release version="1.0-rc5-SNAPSHOT" date="IN Subversion">
+ <action dev="sgoeschl" type="update">
+ Refactoring the code to seperate creation of a MimeMessage and sending
it.
+ </action>
<action dev="dion" type="update">Add serialVersionUID to
EmailException</action>
<action dev="dion" type="update">Use Dumbster 1.6 compiled with jdk13
for testing</action>
<action dev="dion" type="fix" issue="34919" due-to="Eric Spiegelberg">
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]