Source Code Cross Referenced for SendMail.java in  » Workflow-Engines » osbl-1_0 » org » concern » library » 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 » Workflow Engines » osbl 1_0 » org.concern.library.mail 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.concern.library.mail;
002:
003:        import org.concern.controller.AbstractSynchronousActivity;
004:        import org.concern.controller.ActivityExecutionException;
005:        import org.conform.format.TemplateFormat;
006:
007:        import javax.mail.*;
008:        import javax.mail.internet.*;
009:        import java.util.*;
010:        import java.sql.Timestamp;
011:
012:        import ognl.Ognl;
013:        import ognl.OgnlException;
014:
015:        /**
016:         * @author hengels
017:         * @version $Revision$
018:         */
019:        public class SendMail extends AbstractSynchronousActivity {
020:            private String from;
021:            private String to;
022:            private String cc;
023:            private String subject;
024:            private String body;
025:            private String flag;
026:            private String stamp;
027:
028:            public String getFrom() {
029:                return from;
030:            }
031:
032:            public void setFrom(String from) {
033:                this .from = from;
034:            }
035:
036:            public String getTo() {
037:                return to;
038:            }
039:
040:            public void setTo(String to) {
041:                this .to = to;
042:            }
043:
044:            public String getCc() {
045:                return cc;
046:            }
047:
048:            public void setCc(String cc) {
049:                this .cc = cc;
050:            }
051:
052:            public String getSubject() {
053:                return subject;
054:            }
055:
056:            public void setSubject(String subject) {
057:                this .subject = subject;
058:            }
059:
060:            public String getBody() {
061:                return body;
062:            }
063:
064:            public void setBody(String body) {
065:                this .body = body;
066:            }
067:
068:            public String getFlag() {
069:                return flag;
070:            }
071:
072:            public void setFlag(String flag) {
073:                this .flag = flag;
074:            }
075:
076:            public String getStamp() {
077:                return stamp;
078:            }
079:
080:            public void setStamp(String stamp) {
081:                this .stamp = stamp;
082:            }
083:
084:            public void execute(Object subject)
085:                    throws ActivityExecutionException {
086:                Transport transport = null;
087:                try {
088:                    Map context = new HashMap();
089:                    context.put("subject", subject);
090:                    context.putAll(environment);
091:
092:                    javax.mail.Session mailSession = (javax.mail.Session) controller
093:                            .getResourceLocator().lookup("mailSession");
094:                    MimeMessage message = new MimeMessage(mailSession);
095:                    message.setFrom(from(context));
096:                    message
097:                            .setRecipients(Message.RecipientType.TO,
098:                                    to(context));
099:                    message
100:                            .setRecipients(Message.RecipientType.CC,
101:                                    cc(context));
102:                    message.setSubject(new TemplateFormat(getSubject())
103:                            .format(context));
104:                    message.setText(new TemplateFormat(getBody())
105:                            .format(context));
106:
107:                    if (message.getRecipients(Message.RecipientType.TO) != null
108:                            && message.getRecipients(Message.RecipientType.TO).length > 0) {
109:                        transport = mailSession.getTransport("smtp");
110:                        transport.connect();
111:                        transport.sendMessage(message, message
112:                                .getRecipients(Message.RecipientType.TO));
113:                    }
114:
115:                    mark(subject);
116:                } catch (Exception e) {
117:                    e.printStackTrace();
118:                } finally {
119:                    try {
120:                        if (transport != null)
121:                            transport.close();
122:                    } catch (MessagingException e) {
123:                    }
124:                }
125:            }
126:
127:            protected InternetAddress from(Map context) throws AddressException {
128:                try {
129:                    return new InternetAddress((String) Ognl.getValue(
130:                            getFrom(), context));
131:                } catch (OgnlException e) {
132:                    return null;
133:                }
134:            }
135:
136:            // TODO: multiple TOs
137:            protected InternetAddress[] to(Map context) throws AddressException {
138:                try {
139:                    return new InternetAddress[] { new InternetAddress(
140:                            (String) Ognl.getValue(getTo(), context)) };
141:                } catch (OgnlException e) {
142:                    return null;
143:                }
144:            }
145:
146:            // TODO: multiple CCs
147:            protected InternetAddress[] cc(Map context) throws AddressException {
148:                try {
149:                    return new InternetAddress[] { new InternetAddress(
150:                            (String) Ognl.getValue(getCc(), context)) };
151:                } catch (OgnlException e) {
152:                    return null;
153:                }
154:            }
155:
156:            protected void mark(Object subject)
157:                    throws ActivityExecutionException {
158:                try {
159:                    if (flag != null)
160:                        Ognl.setValue(flag, subject, true);
161:                } catch (OgnlException e) {
162:                    throw new ActivityExecutionException(flag + ": "
163:                            + e.getMessage());
164:                }
165:                try {
166:                    if (stamp != null)
167:                        Ognl.setValue(stamp, subject, new Timestamp(System
168:                                .currentTimeMillis()));
169:                } catch (OgnlException e) {
170:                    throw new ActivityExecutionException(stamp + ": "
171:                            + e.getMessage());
172:                }
173:            }
174:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.