Source Code Cross Referenced for SendEmail.java in  » Workflow-Engines » OSWorkflow » com » opensymphony » workflow » util » 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 » OSWorkflow » com.opensymphony.workflow.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright (c) 2002-2003 by OpenSymphony
003:         * All rights reserved.
004:         */
005:        package com.opensymphony.workflow.util;
006:
007:        import com.opensymphony.module.propertyset.PropertySet;
008:
009:        import com.opensymphony.workflow.FunctionProvider;
010:        import com.opensymphony.workflow.config.Configuration;
011:
012:        import org.apache.commons.logging.Log;
013:        import org.apache.commons.logging.LogFactory;
014:
015:        import java.util.*;
016:
017:        import javax.mail.*;
018:        import javax.mail.internet.InternetAddress;
019:        import javax.mail.internet.MimeMessage;
020:
021:        /**
022:         * Sends an email to a group of users. The following arguments are expected:
023:         *
024:         * <ul>
025:         *  <li>to - comma seperated list of email addresses</li>
026:         *  <li>from - single email address</li>
027:         *  <li>subject - the message subject</li>
028:         *  <li>cc - comma seperated list of email addresses (optional)</li>
029:         *  <li>message - the message body</li>
030:         *  <li>smtpHost - the SMTP host that will relay the message</li>
031:         *  <li>parseVariables - if 'true', then variables of the form ${} in subject,
032:         *   message, to, and cc fields will be parsed</li>
033:         * </ul>
034:         *
035:         * @author <a href="mailto:plightbo@hotmail.com">Pat Lightbody</a>
036:         */
037:        public class SendEmail implements  FunctionProvider {
038:            //~ Static fields/initializers /////////////////////////////////////////////
039:
040:            private static final Log log = LogFactory.getLog(SendEmail.class);
041:
042:            //~ Methods ////////////////////////////////////////////////////////////////
043:
044:            public void execute(Map transientVars, Map args, PropertySet ps) {
045:                String to = (String) args.get("to");
046:                String from = (String) args.get("from");
047:                String subject = (String) args.get("subject");
048:                String cc = (String) args.get("cc");
049:                String m = (String) args.get("message");
050:                String smtpHost = (String) args.get("smtpHost");
051:                boolean parseVariables = "true".equals(args
052:                        .get("parseVariables"));
053:                Configuration config = (Configuration) transientVars
054:                        .get("configuration");
055:
056:                try {
057:                    Properties props = new Properties();
058:                    props.put("mail.smtp.host", smtpHost);
059:
060:                    Session sendMailSession = Session.getInstance(props, null);
061:                    Transport transport = sendMailSession.getTransport("smtp");
062:                    Message message = new MimeMessage(sendMailSession);
063:
064:                    message.setFrom(new InternetAddress(from));
065:
066:                    Set toSet = new HashSet();
067:                    VariableResolver variableResolver = config
068:                            .getVariableResolver();
069:                    StringTokenizer st = new StringTokenizer(
070:                            parseVariables ? variableResolver
071:                                    .translateVariables(to, transientVars, ps)
072:                                    .toString() : to, ", ");
073:
074:                    while (st.hasMoreTokens()) {
075:                        String user = st.nextToken();
076:                        toSet.add(new InternetAddress(user));
077:                    }
078:
079:                    message
080:                            .setRecipients(Message.RecipientType.TO,
081:                                    (InternetAddress[]) toSet
082:                                            .toArray(new InternetAddress[toSet
083:                                                    .size()]));
084:
085:                    Set ccSet = null;
086:
087:                    if (cc != null) {
088:                        ccSet = new HashSet();
089:
090:                        if (parseVariables) {
091:                            cc = variableResolver.translateVariables(cc,
092:                                    transientVars, ps).toString();
093:                        }
094:
095:                        st = new StringTokenizer(cc, ", ");
096:
097:                        while (st.hasMoreTokens()) {
098:                            String user = st.nextToken();
099:                            ccSet.add(new InternetAddress(user));
100:                        }
101:                    }
102:
103:                    if ((ccSet != null) && (ccSet.size() > 0)) {
104:                        message.setRecipients(Message.RecipientType.CC,
105:                                (InternetAddress[]) ccSet
106:                                        .toArray(new InternetAddress[ccSet
107:                                                .size()]));
108:                    }
109:
110:                    message.setSubject(parseVariables ? variableResolver
111:                            .translateVariables(subject, transientVars, ps)
112:                            .toString() : subject);
113:                    message.setSentDate(new Date());
114:                    message.setText(parseVariables ? variableResolver
115:                            .translateVariables(m, transientVars, ps)
116:                            .toString() : m);
117:                    message.saveChanges();
118:
119:                    transport.connect();
120:                    transport.sendMessage(message, message.getAllRecipients());
121:                    transport.close();
122:                } catch (MessagingException e) {
123:                    log.error("Error sending email:", e);
124:                }
125:            }
126:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.