2006/unicorn/src/org/w3c/unicorn/output MailOutputModule.java,1.2,1.3

Update of /sources/public/2006/unicorn/src/org/w3c/unicorn/output
In directory hutz:/tmp/cvs-serv20275/src/org/w3c/unicorn/output

Modified Files:
	MailOutputModule.java 
Log Message:
uses mail.properties to connect to the smtp server

Index: MailOutputModule.java
===================================================================
RCS file: /sources/public/2006/unicorn/src/org/w3c/unicorn/output/MailOutputModule.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- MailOutputModule.java	23 Sep 2009 09:28:05 -0000	1.2
+++ MailOutputModule.java	23 Sep 2009 13:02:05 -0000	1.3
@@ -6,12 +6,16 @@
 
 import java.io.CharArrayWriter;
 import java.io.IOException;
+import java.io.UnsupportedEncodingException;
 import java.io.Writer;
+import java.util.Date;
 import java.util.Map;
 import javax.mail.*;
 import javax.mail.internet.*;
 
 import java.util.*; 
+import org.w3c.unicorn.util.Property;
+import org.w3c.unicorn.util.mail.UnicornAuthenticator;
 
 /**
  * This module allow to generate output in mail format.
@@ -35,79 +39,64 @@
 		this.mapOfSpecificParameters = mapOfSpecificParameters;
 		this.recipient = mapOfSpecificParameters.get("email");
 			
+		String format = mapOfOutputParameters.get("format");
+		String lang = mapOfOutputParameters.get("lang"); 
+		String mimeType = mapOfOutputParameters.get("mimetype");
 		
-		aOutputFormater = OutputFactory.createOutputFormater(mapOfOutputParameters.get("format"),
-				mapOfOutputParameters.get("lang"), mapOfOutputParameters.get("mimetype"));
+		aOutputFormater = OutputFactory.createOutputFormater(format, lang, mimeType);
 		
-		mailOutputFormater = OutputFactory.createOutputFormater(mapOfSpecificParameters.get("format"),
-				mapOfOutputParameters.get("lang"), mapOfOutputParameters.get("mimetype"));
+		if (mapOfSpecificParameters.get("format") != null)
+			format = mapOfSpecificParameters.get("format");
 		
+		mailOutputFormater = OutputFactory.createOutputFormater(format, lang, mimeType);
 	}
 	
 	public void produceFirstOutput(Map<String, Object> mapOfStringObject, Writer aWriter) {
-		
 		try {
 			aWriter.append("mail en cours d'envoi.");
 			aWriter.close();
 		} catch (IOException e) {
-			// TODO Auto-generated catch block
-			System.out.println("TOOOOOO");
 			e.printStackTrace();
 		}
 	}
 	
 	public void produceOutput(Map<String, Object> mapOfStringObject, final Writer aWriter) {
-		
-		/*try {
-			aWriter.close();
-		} catch (IOException e) {
-			// TODO Auto-generated catch block
-			System.out.println("TOOOOOO");
-			e.printStackTrace();
-		}*/
-		
-	    Properties props = new Properties();
-	    props.put("mail.smtp.starttls.enable","true");
-	    //props.put("mail.smtp.user", "thomas.gambet@gmail.com");
 	    
 		try {
-			Session session = Session.getDefaultInstance(props, null);
+			Properties mailProps = Property.getProps("mail.properties");
+			Authenticator auth = new UnicornAuthenticator(mailProps.getProperty("unicorn.mail.username"), mailProps.getProperty("unicorn.mail.password"));
+			Session session = Session.getDefaultInstance(mailProps, auth);
 		    session.setDebug(true);
 		    Message msg = new MimeMessage(session);
-			
-		    InternetAddress addressFrom = new InternetAddress("thomas.gambet@gmail.com");
+		    
+		    InternetAddress addressFrom = new InternetAddress(mailProps.getProperty("unicorn.mail.from"), "Unicorn");
 			msg.setFrom(addressFrom);
 			
 			InternetAddress[] adresses = {new InternetAddress(recipient)};
 			msg.setRecipients(Message.RecipientType.TO, adresses);
 			
 			// Setting the Subject and Content Type
-			msg.setSubject("test subject");
+			msg.setSubject("Unicorn results, " + new Date());
 			
 			CharArrayWriter writer = new CharArrayWriter();
 			mailOutputFormater.produceOutput(mapOfStringObject, writer);
 			writer.close();
-			
 			msg.setContent(writer.toString(), mapOfOutputParameters.get("mimetype"));
 			
-			Transport transport = session.getTransport("smtp");
-			transport.connect("smtp.gmail.com", "eric.gambet@gmail.com", "36153615");
-			transport.sendMessage(msg, msg.getAllRecipients());
-			//aOutputFormater.produceOutput(mapOfStringObject, aWriter);
-			//aWriter.close();
+			Transport.send(msg);
 		} catch (AddressException e) {
 			// TODO Auto-generated catch block
 			e.printStackTrace();
 		} catch (MessagingException e) {
 			// TODO Auto-generated catch block
 			e.printStackTrace();
+		} catch (UnsupportedEncodingException e) {
+			// TODO Auto-generated catch block
+			e.printStackTrace();
 		} 
 	}
 
 	public void produceError(Map<String, Object> mapOfStringObject, final Writer aWriter) {
-		
-		
-		
 		aOutputFormater.produceError(mapOfStringObject, aWriter);
 	}
 
@@ -115,6 +104,4 @@
 		return mapOfOutputParameters.get(string);
 	}
 
-
-
-}
+}
\ No newline at end of file

Received on Wednesday, 23 September 2009 13:02:17 UTC