Source Code Cross Referenced for WikiMail.java in  » Wiki-Engine » JAMWiki » org » jamwiki » mail » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Wiki Engine » JAMWiki » org.jamwiki.mail 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE, version 2.1, dated February 1999.
003:         *
004:         * This program is free software; you can redistribute it and/or modify
005:         * it under the terms of the latest version of the GNU Lesser General
006:         * Public License as published by the Free Software Foundation;
007:         *
008:         * This program is distributed in the hope that it will be useful,
009:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
010:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
011:         * GNU Lesser General Public License for more details.
012:         *
013:         * You should have received a copy of the GNU Lesser General Public License
014:         * along with this program (LICENSE.txt); if not, write to the Free Software
015:         * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
016:         */package org.jamwiki.mail;
017:
018:        import java.util.Date;
019:        import java.util.Properties;
020:        import javax.mail.Message;
021:        import javax.mail.MessagingException;
022:        import javax.mail.Session;
023:        import javax.mail.Transport;
024:        import javax.mail.internet.InternetAddress;
025:        import javax.mail.internet.MimeMessage;
026:        import org.jamwiki.Environment;
027:        import org.jamwiki.utils.WikiLogger;
028:
029:        /**
030:         * Sends mail via SMTP to the specified host. <b>REDISTRIBUTION:</b> you
031:         * will either have to hard-code your own SMTP host name into the constructor
032:         * function and recompile, or rewrite the Environment class to record
033:         * this information in the jamwiki.properties file.
034:         */
035:        public class WikiMail {
036:
037:            private static final WikiLogger logger = WikiLogger
038:                    .getLogger(WikiMail.class.getName());
039:            private final Session session;
040:            private static WikiMail instance;
041:
042:            /**
043:             * Construct the object by opening a JavaMail session. Use getInstance to provide Singleton behavior.
044:             */
045:            public WikiMail() {
046:                Properties props = System.getProperties();
047:                props.setProperty("mail.smtp.host", Environment
048:                        .getValue(Environment.PROP_EMAIL_SMTP_HOST));
049:                if (Environment.getValue(Environment.PROP_EMAIL_SMTP_USERNAME)
050:                        .equals("")) {
051:                    session = Session.getInstance(props, null);
052:                } else {
053:                    session = Session.getInstance(props,
054:                            new WikiMailAuthenticator());
055:                }
056:            }
057:
058:            /**
059:             * Provide a Singleton instance of the object.
060:             */
061:            public static WikiMail getInstance() {
062:                if (instance == null) {
063:                    instance = new WikiMail();
064:                }
065:                return instance;
066:            }
067:
068:            /**
069:             * Send mail via SMTP. MessagingExceptions are silently dropped.
070:             *
071:             * @param from the RFC 821 "MAIL FROM" parameter
072:             * @param to the RFC 821 "RCPT TO" parameter
073:             * @param subject the RFC 822 "Subject" field
074:             * @param body the RFC 822 "Body" field
075:             */
076:            public void sendMail(String from, String to, String subject,
077:                    String body) {
078:                try {
079:                    MimeMessage message = new MimeMessage(session);
080:                    InternetAddress internetAddress = new InternetAddress(from);
081:                    message.setFrom(internetAddress);
082:                    message
083:                            .setReplyTo(new InternetAddress[] { internetAddress });
084:                    message.setRecipient(Message.RecipientType.TO,
085:                            new InternetAddress(to));
086:                    message.setSubject(subject);
087:                    message.setText(body);
088:                    message.setSentDate(new Date());
089:                    message.saveChanges();
090:                    Transport.send(message);
091:                } catch (MessagingException e) {
092:                    logger.warning("Mail error", e);
093:                }
094:            }
095:
096:            /**
097:             *
098:             */
099:            public static void init() {
100:                instance = null;
101:            }
102:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.