[ThorFramework-devel] SF.net SVN: thorframework: [26] trunk/thor/src/org/y2k1
Status: Planning
Brought to you by:
denniskempin
|
From: <den...@us...> - 2006-02-25 21:45:31
|
Revision: 26 Author: denniskempin Date: 2006-02-25 13:45:20 -0800 (Sat, 25 Feb 2006) ViewCVS: http://svn.sourceforge.net/thorframework/?rev=26&view=rev Log Message: ----------- Added Paths: ----------- trunk/thor/src/org/y2k1/thorx/ trunk/thor/src/org/y2k1/thorx/modules/ trunk/thor/src/org/y2k1/thorx/modules/MailSender.java Removed Paths: ------------- trunk/thor/src/org/y2k1/thor/modules/ Copied: trunk/thor/src/org/y2k1/thorx/modules/MailSender.java (from rev 24, trunk/thor/src/org/y2k1/thor/modules/MailSender.java) =================================================================== --- trunk/thor/src/org/y2k1/thorx/modules/MailSender.java (rev 0) +++ trunk/thor/src/org/y2k1/thorx/modules/MailSender.java 2006-02-25 21:45:20 UTC (rev 26) @@ -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.thorx.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. |