Java Doc for MailMessage.java in  » Build » ANT » org » apache » tools » 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 » Build » ANT » org.apache.tools.mail 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   org.apache.tools.mail.MailMessage

MailMessage
public class MailMessage (Code)
A class to help send SMTP email. This class is an improvement on the sun.net.smtp.SmtpClient class found in the JDK. This version has extra functionality, and can be used with JVMs that did not extend from the JDK. It's not as robust as the JavaMail Standard Extension classes, but it's easier to use and easier to install, and has an Open Source license.

It can be used like this:

 String mailhost = "localhost";  // or another mail host
 String from = "Mail Message Servlet <MailMessage@server.com>";
 String to = "to@you.com";
 String cc1 = "cc1@you.com";
 String cc2 = "cc2@you.com";
 String bcc = "bcc@you.com";
  
 MailMessage msg = new MailMessage(mailhost);
 msg.setPort(25);
 msg.from(from);
 msg.to(to);
 msg.cc(cc1);
 msg.cc(cc2);
 msg.bcc(bcc);
 msg.setSubject("Test subject");
 PrintStream out = msg.getPrintStream();
  
 Enumeration enum = req.getParameterNames();
 while (enum.hasMoreElements()) {
 String name = (String)enum.nextElement();
 String value = req.getParameter(name);
 out.println(name + " = " + value);
 }
  
 msg.sendAndClose();
 

Be sure to set the from address, then set the recepient addresses, then set the subject and other headers, then get the PrintStream, then write the message, and finally send and close. The class does minimal error checking internally; it counts on the mail host to complain if there's any malformatted input or out of order execution.

An attachment mechanism based on RFC 1521 could be implemented on top of this class. In the meanwhile, JavaMail is the best solution for sending email with attachments.

Still to do:

  • Figure out how to close the connection in case of error

version:
   1.1, 2000/03/19, added angle brackets to address, helps some servers
version:
   version 1.0, 1999/12/29


Field Summary
final public static  StringDEFAULT_HOST
    
final public static  intDEFAULT_PORT
    

Constructor Summary
public  MailMessage()
     Constructs a new MailMessage to send an email.
public  MailMessage(String host)
     Constructs a new MailMessage to send an email.
public  MailMessage(String host, int port)
     Constructs a new MailMessage to send an email.

Method Summary
public  voidbcc(String bcc)
     Sets the bcc address.
public  voidcc(String cc)
     Sets the cc address.
 voidconnect()
    
 voiddisconnect()
    
 voidflushHeaders()
    
public  voidfrom(String from)
     Sets the from address.
public  PrintStreamgetPrintStream()
     Returns a PrintStream that can be used to write the body of the message. A stream is used since email bodies are byte-oriented.
 voidgetReady()
    
 booleanisResponseOK(String response, int[] ok)
    
public  voidreplyto(String rto)
     Sets the replyto address This method may be called multiple times.
static  StringsanitizeAddress(String s)
    
 voidsend(String msg, int[] ok)
    
public  voidsendAndClose()
     Sends the message and closes the connection to the server.
 voidsendData()
    
 voidsendDot()
    
 voidsendFrom(String from)
    
 voidsendHelo()
    
 voidsendQuit()
    
 voidsendRcpt(String rcpt)
    
 voidsetCcHeader()
    
 voidsetFromHeader()
    
public  voidsetHeader(String name, String value)
     Sets the named header to the given value.
public  voidsetPort(int port)
     Set the port to connect to the SMTP host.
 voidsetReplyToHeader()
    
public  voidsetSubject(String subj)
     Sets the subject of the mail message.
 voidsetToHeader()
    
public  voidto(String to)
     Sets the to address.
 StringvectorToList(Vector v)
    

Field Detail
DEFAULT_HOST
final public static String DEFAULT_HOST(Code)
default mailhost



DEFAULT_PORT
final public static int DEFAULT_PORT(Code)
default port for SMTP: 25




Constructor Detail
MailMessage
public MailMessage() throws IOException(Code)
Constructs a new MailMessage to send an email. Use localhost as the mail server with port 25.
exception:
  IOException - if there's any problem contacting the mail server



MailMessage
public MailMessage(String host) throws IOException(Code)
Constructs a new MailMessage to send an email. Use the given host as the mail server with port 25.
Parameters:
  host - the mail server to use
exception:
  IOException - if there's any problem contacting the mail server



MailMessage
public MailMessage(String host, int port) throws IOException(Code)
Constructs a new MailMessage to send an email. Use the given host and port as the mail server.
Parameters:
  host - the mail server to use
Parameters:
  port - the port to connect to
exception:
  IOException - if there's any problem contacting the mail server




Method Detail
bcc
public void bcc(String bcc) throws IOException(Code)
Sets the bcc address. Does NOT set any header since it's a *blind* copy. This method may be called multiple times.
Parameters:
  bcc - the bcc address
exception:
  IOException - if there's any problem reported by the mail server



cc
public void cc(String cc) throws IOException(Code)
Sets the cc address. Also sets the "Cc" header. This method may be called multiple times.
Parameters:
  cc - the cc address
exception:
  IOException - if there's any problem reported by the mail server



connect
void connect() throws IOException(Code)



disconnect
void disconnect() throws IOException(Code)



flushHeaders
void flushHeaders() throws IOException(Code)



from
public void from(String from) throws IOException(Code)
Sets the from address. Also sets the "From" header. This method should be called only once.
Parameters:
  from - the from address
exception:
  IOException - if there's any problem reported by the mail server



getPrintStream
public PrintStream getPrintStream() throws IOException(Code)
Returns a PrintStream that can be used to write the body of the message. A stream is used since email bodies are byte-oriented. A writer can be wrapped on top if necessary for internationalization. This is actually done in Message.java a printstream containing the data and the headers of the email
exception:
  IOException - if there's any problem reported by the mail server
See Also:   org.apache.tools.ant.taskdefs.email.Message



getReady
void getReady() throws IOException(Code)



isResponseOK
boolean isResponseOK(String response, int[] ok)(Code)



replyto
public void replyto(String rto)(Code)
Sets the replyto address This method may be called multiple times.
Parameters:
  rto - the replyto address



sanitizeAddress
static String sanitizeAddress(String s)(Code)



send
void send(String msg, int[] ok) throws IOException(Code)



sendAndClose
public void sendAndClose() throws IOException(Code)
Sends the message and closes the connection to the server. The MailMessage object cannot be reused.
exception:
  IOException - if there's any problem reported by the mail server



sendData
void sendData() throws IOException(Code)



sendDot
void sendDot() throws IOException(Code)



sendFrom
void sendFrom(String from) throws IOException(Code)



sendHelo
void sendHelo() throws IOException(Code)



sendQuit
void sendQuit() throws IOException(Code)



sendRcpt
void sendRcpt(String rcpt) throws IOException(Code)



setCcHeader
void setCcHeader()(Code)



setFromHeader
void setFromHeader()(Code)



setHeader
public void setHeader(String name, String value)(Code)
Sets the named header to the given value. RFC 822 provides the rules for what text may constitute a header name and value.
Parameters:
  name - name of the header
Parameters:
  value - contents of the header



setPort
public void setPort(int port)(Code)
Set the port to connect to the SMTP host.
Parameters:
  port - the port to use for connection.
See Also:   MailMessage.DEFAULT_PORT



setReplyToHeader
void setReplyToHeader()(Code)



setSubject
public void setSubject(String subj)(Code)
Sets the subject of the mail message. Actually sets the "Subject" header.
Parameters:
  subj - the subject of the mail message



setToHeader
void setToHeader()(Code)



to
public void to(String to) throws IOException(Code)
Sets the to address. Also sets the "To" header. This method may be called multiple times.
Parameters:
  to - the to address
exception:
  IOException - if there's any problem reported by the mail server



vectorToList
String vectorToList(Vector v)(Code)



Methods inherited from java.lang.Object
native protected Object clone() throws CloneNotSupportedException(Code)(Java Doc)
public boolean equals(Object obj)(Code)(Java Doc)
protected void finalize() throws Throwable(Code)(Java Doc)
final native public Class getClass()(Code)(Java Doc)
native public int hashCode()(Code)(Java Doc)
final native public void notify()(Code)(Java Doc)
final native public void notifyAll()(Code)(Java Doc)
public String toString()(Code)(Java Doc)
final native public void wait(long timeout) throws InterruptedException(Code)(Java Doc)
final public void wait(long timeout, int nanos) throws InterruptedException(Code)(Java Doc)
final public void wait() throws InterruptedException(Code)(Java Doc)

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.