Revision: 24
Author: denniskempin
Date: 2006-02-25 13:36:46 -0800 (Sat, 25 Feb 2006)
ViewCVS: http://svn.sourceforge.net/thorframework/?rev=24&view=rev
Log Message:
-----------
added mail send module
Added Paths:
-----------
trunk/thor/lib/mailapi.jar
trunk/thor/src/org/y2k1/thor/modules/
trunk/thor/src/org/y2k1/thor/modules/MailSender.java
Added: trunk/thor/lib/mailapi.jar
===================================================================
(Binary files differ)
Property changes on: trunk/thor/lib/mailapi.jar
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: trunk/thor/src/org/y2k1/thor/modules/MailSender.java
===================================================================
--- trunk/thor/src/org/y2k1/thor/modules/MailSender.java (rev 0)
+++ trunk/thor/src/org/y2k1/thor/modules/MailSender.java 2006-02-25 21:36:46 UTC (rev 24)
@@ -0,0 +1,73 @@
+/*
+ * Copyright 2002-2006 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.y2k1.thor.modules;
+
+import java.util.Properties;
+
+import javax.mail.Message;
+import javax.mail.MessagingException;
+import javax.mail.Session;
+import javax.mail.Transport;
+import javax.mail.internet.MimeMessage;
+
+import org.y2k1.thor.core.Module;
+import org.y2k1.thor.core.ModuleInitializer;
+import org.y2k1.thor.util.KeyNotFoundException;
+
+public final class MailSender extends Module
+{
+ private String host;
+ private String username;
+ private String password;
+ private Session session;
+
+ public MailSender(ModuleInitializer initializer) throws KeyNotFoundException
+ {
+ super(initializer);
+
+ this.host = initializer.getProperty("host", "localhost");
+ this.username = initializer.getProperty("username", "");
+ this.password = initializer.getProperty("password", "");
+
+ Properties properties = new Properties();
+
+ if(!this.username.equals(""))
+ {
+ properties.put("mail.smtp.auth", "true");
+ }
+ if(initializer.getProperty("from", null) != null)
+ {
+ properties.put("mail.smtp.from", initializer.getProperty("from"));
+ }
+
+ this.session = Session.getInstance(properties);
+ }
+
+ public Message createMessage()
+ {
+ return new MimeMessage(this.session);
+ }
+
+ public void sendMessage(Message message) throws MessagingException
+ {
+ message.saveChanges();
+
+ Transport smtp = this.session.getTransport("smtp");
+ smtp.connect(this.host, this.username, this.password);
+ smtp.sendMessage(message, message.getAllRecipients());
+ smtp.close();
+ }
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|