Source Code Cross Referenced for WikiMail.java in  » Wiki-Engine » VeryQuickWiki » vqwiki » 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 » VeryQuickWiki » vqwiki 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package vqwiki;
002:
003:        import org.apache.log4j.Logger;
004:
005:        import javax.mail.Message;
006:        import javax.mail.MessagingException;
007:        import javax.mail.Session;
008:        import javax.mail.Transport;
009:        import javax.mail.internet.InternetAddress;
010:        import javax.mail.internet.MimeMessage;
011:        import java.util.Date;
012:        import java.util.Properties;
013:
014:        /**
015:         * Sends mail via SMTP to the specified host. <b>REDISTRIBUTION:</b> you
016:         * will either have to hard-code your own SMTP host name into the constructor
017:         * function and recompile, or rewrite the Environment class to record
018:         * this information in the vqwiki.properties file.
019:         *
020:         * @author Robert E Brewer
021:         * @version 0.1
022:         */
023:        public class WikiMail {
024:
025:            private static final Logger logger = Logger
026:                    .getLogger(WikiMail.class);
027:            private Session session;
028:            private static WikiMail instance;
029:
030:            /**
031:             * Construct the object by opening a JavaMail session. Use getInstance to provide Singleton behavior.
032:             */
033:            public WikiMail() {
034:                Properties props = System.getProperties();
035:                props.setProperty("mail.smtp.host", Environment.getInstance()
036:                        .getStringSetting(Environment.PROPERTY_SMTP_HOST));
037:                if (Environment.getInstance().getStringSetting(
038:                        Environment.PROPERTY_SMTP_USERNAME).equals("")) {
039:                    session = Session.getInstance(props, null);
040:                } else {
041:                    props.setProperty("mail.smtp.auth", "true");
042:                    session = Session.getInstance(props,
043:                            new WikiMailAuthenticator());
044:                }
045:            }
046:
047:            /**
048:             * Provide a Singleton instance of the object.
049:             */
050:            public static WikiMail getInstance() {
051:                if (instance == null)
052:                    instance = new WikiMail();
053:                return instance;
054:            }
055:
056:            /**
057:             * Send mail via SMTP. MessagingExceptions are silently dropped.
058:             *
059:             * @param from the RFC 821 "MAIL FROM" parameter
060:             * @param to the RFC 821 "RCPT TO" parameter
061:             * @param subject the RFC 822 "Subject" field
062:             * @param body the RFC 822 "Body" field
063:             */
064:            public void sendMail(String from, String to, String subject,
065:                    String body) {
066:                try {
067:                    MimeMessage message = new MimeMessage(session);
068:                    InternetAddress internetAddress = new InternetAddress(from);
069:                    message.setFrom(internetAddress);
070:                    message
071:                            .setReplyTo(new InternetAddress[] { internetAddress });
072:                    message.setRecipient(Message.RecipientType.TO,
073:                            new InternetAddress(to));
074:                    message.setSubject(subject);
075:                    message.setText(body);
076:                    message.setSentDate(new Date());
077:                    message.saveChanges();
078:                    if (!Environment.getInstance().getStringSetting(
079:                            Environment.PROPERTY_SMTP_USERNAME).equals("")
080:                            && !!Environment.getInstance().getStringSetting(
081:                                    Environment.PROPERTY_SMTP_PASSWORD).equals(
082:                                    "")) {
083:                        String username = Environment.getInstance()
084:                                .getStringSetting(
085:                                        Environment.PROPERTY_SMTP_USERNAME);
086:                        String password = Environment.getInstance()
087:                                .getStringSetting(
088:                                        Environment.PROPERTY_SMTP_PASSWORD);
089:                        String smtphost = Environment.getInstance()
090:                                .getStringSetting(
091:                                        Environment.PROPERTY_SMTP_HOST);
092:
093:                        Transport tr = session.getTransport("smtp");
094:                        tr.connect(smtphost, username, password);
095:                        tr.sendMessage(message, message.getAllRecipients());
096:                        tr.close();
097:                    } else {
098:                        Transport.send(message);
099:                    }
100:                } catch (MessagingException e) {
101:                    logger.warn("Mail error", e);
102:                }
103:            }
104:
105:            /**
106:             *
107:             */
108:            public static void init() {
109:                instance = null;
110:            }
111:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.