Source Code Cross Referenced for SimpleSMTPHeader.java in  » Net » Apache-commons-net-1.4.1 » org » apache » commons » net » smtp » 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 » Net » Apache commons net 1.4.1 » org.apache.commons.net.smtp 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2001-2005 The Apache Software Foundation
003:         *
004:         * Licensed under the Apache License, Version 2.0 (the "License");
005:         * you may not use this file except in compliance with the License.
006:         * You may obtain a copy of the License at
007:         *
008:         *     http://www.apache.org/licenses/LICENSE-2.0
009:         *
010:         * Unless required by applicable law or agreed to in writing, software
011:         * distributed under the License is distributed on an "AS IS" BASIS,
012:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013:         * See the License for the specific language governing permissions and
014:         * limitations under the License.
015:         */
016:        package org.apache.commons.net.smtp;
017:
018:        /***
019:         * This class is used to construct a bare minimum
020:         * acceptable header for an email message.  To construct more
021:         * complicated headers you should refer to RFC 822.  When the
022:         * Java Mail API is finalized, you will be
023:         * able to use it to compose fully compliant Internet text messages.
024:         * <p>
025:         * The main purpose of the class is to faciliatate the mail sending
026:         * process, by relieving the programmer from having to explicitly format
027:         * a simple message header.  For example:
028:         * <pre>
029:         * writer = client.sendMessageData();
030:         * if(writer == null) // failure
031:         *   return false;
032:         * header =
033:         *    new SimpleSMTPHeader("foobar@foo.com", "foo@bar.com" "Just testing");
034:         * header.addCC("bar@foo.com");
035:         * header.addHeaderField("Organization", "Foobar, Inc.");
036:         * writer.write(header.toString());
037:         * writer.write("This is just a test");
038:         * writer.close();
039:         * if(!client.completePendingCommand()) // failure
040:         *   return false;
041:         * </pre>
042:         * <p>
043:         * <p>
044:         * @author Daniel F. Savarese
045:         * @see SMTPClient
046:         ***/
047:
048:        public class SimpleSMTPHeader {
049:            private String __subject, __from, __to;
050:            private StringBuffer __headerFields, __cc;
051:
052:            /***
053:             * Creates a new SimpleSMTPHeader instance initialized with the given
054:             * from, to, and subject header field values.
055:             * <p>
056:             * @param from  The value of the <code>From:</code> header field.  This
057:             *              should be the sender's email address.
058:             * @param to    The value of the <code>To:</code> header field.  This
059:             *              should be the recipient's email address.
060:             * @param subject  The value of the <code>Subject:</code> header field.
061:             *              This should be the subject of the message.
062:             ***/
063:            public SimpleSMTPHeader(String from, String to, String subject) {
064:                __to = to;
065:                __from = from;
066:                __subject = subject;
067:                __headerFields = new StringBuffer();
068:                __cc = null;
069:            }
070:
071:            /***
072:             * Adds an arbitrary header field with the given value to the article
073:             * header.  These headers will be written before the From, To, Subject, and
074:             * Cc fields when the SimpleSMTPHeader is convertered to a string.
075:             * An example use would be:
076:             * <pre>
077:             * header.addHeaderField("Organization", "Foobar, Inc.");
078:             * </pre>
079:             * <p>
080:             * @param headerField  The header field to add, not including the colon.
081:             * @param value  The value of the added header field.
082:             ***/
083:            public void addHeaderField(String headerField, String value) {
084:                __headerFields.append(headerField);
085:                __headerFields.append(": ");
086:                __headerFields.append(value);
087:                __headerFields.append('\n');
088:            }
089:
090:            /***
091:             * Add an email address to the CC (carbon copy or courtesy copy) list.
092:             * <p>
093:             * @param address The email address to add to the CC list.
094:             ***/
095:            public void addCC(String address) {
096:                if (__cc == null)
097:                    __cc = new StringBuffer();
098:                else
099:                    __cc.append(", ");
100:
101:                __cc.append(address);
102:            }
103:
104:            /***
105:             * Converts the SimpleSMTPHeader to a properly formatted header in
106:             * the form of a String, including the blank line used to separate
107:             * the header from the article body.  The header fields CC and Subject
108:             * are only included when they are non-null.
109:             * <p>
110:             * @return The message header in the form of a String.
111:             ***/
112:            public String toString() {
113:                StringBuffer header = new StringBuffer();
114:
115:                if (__headerFields.length() > 0)
116:                    header.append(__headerFields.toString());
117:
118:                header.append("From: ");
119:                header.append(__from);
120:                header.append("\nTo: ");
121:                header.append(__to);
122:
123:                if (__cc != null) {
124:                    header.append("\nCc: ");
125:                    header.append(__cc.toString());
126:                }
127:
128:                if (__subject != null) {
129:                    header.append("\nSubject: ");
130:                    header.append(__subject);
131:                }
132:
133:                header.append('\n');
134:                header.append('\n');
135:
136:                return header.toString();
137:            }
138:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.