Board: FTC QA

Subject

CVS: Email.java 1.3 1.4

Author

Tim Pizey

Status

Date

17/01/2006 21:43

Message

Update of /usr/cvsroot/org/paneris/ftc/controller
In directory rama.paneris.org:/tmp/cvs-serv2457/src/java/org/paneris/ftc/controller
Modified Files:
Email.java
Log Message:
Add deprecated methods
Index: Email.java
===================================================================
RCS file: /usr/cvsroot/org/paneris/ftc/controller/Email.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- Email.java 25 May 2003 21:25:03 -0000 1.3
+++ Email.java 17 Jan 2006 21:43:02 -0000 1.4
@@ -1,28 +1,25 @@
package org.paneris.ftc.controller;

-import javax.mail.Session;
-import javax.mail.internet.MimeMessage;
-import javax.mail.internet.MimeBodyPart;
-import javax.mail.Multipart;
-import javax.mail.internet.MimeMultipart;
-import javax.mail.internet.InternetAddress;
+import java.io.File;
+import java.io.IOException;
+
+import javax.activation.DataHandler;
+import javax.activation.FileDataSource;
import javax.mail.Address;
import javax.mail.Message;
+import javax.mail.Multipart;
+import javax.mail.Session;
import javax.mail.Transport;
-import javax.activation.DataHandler;
-import javax.activation.FileDataSource;
-
-import java.io.File;
-
-import java.io.IOException;
-import java.text.SimpleDateFormat;
+import javax.mail.internet.InternetAddress;
+import javax.mail.internet.MimeBodyPart;
+import javax.mail.internet.MimeMessage;
+import javax.mail.internet.MimeMultipart;

import org.melati.poem.Database;

/*
* This class sends an email with attachments.
*
- *
* @author timp@paneris.org
* $Revision$
*/
@@ -31,37 +28,48 @@

public static String SMTPSERVER = "SMTPServer";

- static SimpleDateFormat formatter =
- new SimpleDateFormat("dd MMM yyyy hh:mm:ss zzz");
-
+ /**
+ * @deprecated try to disentangle poem and utils
+ */
+ public static void send(Database database, String from, String to,
+ String replyto, String subject, String text)
+ throws EmailException, IOException {
+ File[] empty = {};
+ String smtpServer = database.getSettingTable().get(SMTPSERVER);
+ sendWithAttachments(smtpServer, from, to, replyto, subject, text, empty);
+ }

- public static void send(Database database,
- String from,
- String to,
- String replyto,
- String subject,
- String text) throws EmailException,
- IOException {
- File [] empty = {};
- sendWithAttachments(database, from, to, replyto, subject, text, empty);
- }
+ public static void send(String smtpServer, String from, String to,
+ String replyto, String subject, String text)
+ throws EmailException, IOException {
+ File[] empty = {};
+ sendWithAttachments(smtpServer, from, to, replyto, subject, text, empty);
+ }

- public static void sendWithAttachments(Database database,
- String from,
- String to,
- String replyto,
- String subject,
- String text,
- File[] files) throws EmailException,
- IOException {
+ /**
+ * @deprecated try to disentangle poem and utils
+ */
+ public static void sendWithAttachments(Database database, String from,
+ String to, String replyto,
+ String subject, String text,
+ File[] files)
+ throws EmailException, IOException {
// Get our smtp server from the database
- String smtpserver = database.getSettingTable().get(SMTPSERVER);
+ String smtpServer = database.getSettingTable().get(SMTPSERVER);
+ sendWithAttachments(smtpServer, from, to, replyto, subject, text, files);
+ }
+
+ public static void sendWithAttachments(String smtpServer, String from,
+ String to, String replyto,
+ String subject, String text,
+ File[] files)
+ throws EmailException, IOException {

// Create the JavaMail session
- // The properties for the whole system, sufficient to send a mail
+ // The properties for the whole system, sufficient to send a mail
// and much more besides.
java.util.Properties properties = System.getProperties();
- properties.put("mail.smtp.host", smtpserver);
+ properties.put("mail.smtp.host", smtpServer);

Session session = Session.getInstance(properties, null);

@@ -76,15 +84,14 @@
// Parse and set the recipient addresses
Address[] toAddresses = InternetAddress.parse(to);

- message.setRecipients(Message.RecipientType.TO,toAddresses);
-/*
- Address[] ccAddresses = InternetAddress.parse(cc);
- message.setRecipients(Message.RecipientType.CC,ccAddresses);
-
- Address[] bccAddresses = InternetAddress.parse(bcc);
- message.setRecipients(Message.RecipientType.BCC,bccAddresses);
-*/
-
+ message.setRecipients(Message.RecipientType.TO, toAddresses);
+ /*
+ * Address[] ccAddresses = InternetAddress.parse(cc);
+ * message.setRecipients(Message.RecipientType.CC,ccAddresses);
+ *
+ * Address[] bccAddresses = InternetAddress.parse(bcc);
+ * message.setRecipients(Message.RecipientType.BCC,bccAddresses);
+ */

message.setSubject(subject);

@@ -95,7 +102,7 @@
Multipart mp = new MimeMultipart();
mp.addBodyPart(mbp1);

- for (int i=0; i < files.length; i++) {
+ for (int i = 0; i < files.length; i++) {
// create the second message part
MimeBodyPart mbp2 = new MimeBodyPart();

@@ -112,17 +119,10 @@
// send the message
Transport.send(message);

-
} catch (Exception e) {
throw new EmailException("Problem creating message: " + e.toString());
}

-
}

}
-
-
-
-
-

FTC QA Board

 

Post Follow-up

Search This Board

 



Home -  News -  Reference Sites -  Members -  Partners -  Guidelines -  Philosophy -  Your Details -  Logout