????
| Current Path : /opt/ant/manual/api/org/apache/tools/mail/ |
| Current File : //opt/ant/manual/api/org/apache/tools/mail/MailMessage.html |
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<!-- NewPage -->
<html lang="en">
<head>
<!-- Generated by javadoc (version 1.7.0_03) on Tue May 22 06:24:55 CEST 2012 -->
<title>MailMessage (Apache Ant API)</title>
<meta name="date" content="2012-05-22">
<link rel="stylesheet" type="text/css" href="../../../../stylesheet.css" title="Style">
</head>
<body>
<script type="text/javascript"><!--
if (location.href.indexOf('is-external=true') == -1) {
parent.document.title="MailMessage (Apache Ant API)";
}
//-->
</script>
<noscript>
<div>JavaScript is disabled on your browser.</div>
</noscript>
<!-- ========= START OF TOP NAVBAR ======= -->
<div class="topNav"><a name="navbar_top">
<!-- -->
</a><a href="#skip-navbar_top" title="Skip navigation links"></a><a name="navbar_top_firstrow">
<!-- -->
</a>
<ul class="navList" title="Navigation">
<li><a href="../../../../overview-summary.html">Overview</a></li>
<li><a href="package-summary.html">Package</a></li>
<li class="navBarCell1Rev">Class</li>
<li><a href="package-tree.html">Tree</a></li>
<li><a href="../../../../deprecated-list.html">Deprecated</a></li>
<li><a href="../../../../index-all.html">Index</a></li>
<li><a href="../../../../help-doc.html">Help</a></li>
</ul>
</div>
<div class="subNav">
<ul class="navList">
<li><a href="../../../../org/apache/tools/mail/ErrorInQuitException.html" title="class in org.apache.tools.mail"><span class="strong">Prev Class</span></a></li>
<li><a href="../../../../org/apache/tools/mail/SmtpResponseReader.html" title="class in org.apache.tools.mail"><span class="strong">Next Class</span></a></li>
</ul>
<ul class="navList">
<li><a href="../../../../index.html?org/apache/tools/mail/MailMessage.html" target="_top">Frames</a></li>
<li><a href="MailMessage.html" target="_top">No Frames</a></li>
</ul>
<ul class="navList" id="allclasses_navbar_top">
<li><a href="../../../../allclasses-noframe.html">All Classes</a></li>
</ul>
<div>
<script type="text/javascript"><!--
allClassesLink = document.getElementById("allclasses_navbar_top");
if(window==top) {
allClassesLink.style.display = "block";
}
else {
allClassesLink.style.display = "none";
}
//-->
</script>
</div>
<div>
<ul class="subNavList">
<li>Summary: </li>
<li>Nested | </li>
<li><a href="#field_summary">Field</a> | </li>
<li><a href="#constructor_summary">Constr</a> | </li>
<li><a href="#method_summary">Method</a></li>
</ul>
<ul class="subNavList">
<li>Detail: </li>
<li><a href="#field_detail">Field</a> | </li>
<li><a href="#constructor_detail">Constr</a> | </li>
<li><a href="#method_detail">Method</a></li>
</ul>
</div>
<a name="skip-navbar_top">
<!-- -->
</a></div>
<!-- ========= END OF TOP NAVBAR ========= -->
<!-- ======== START OF CLASS DATA ======== -->
<div class="header">
<div class="subTitle">org.apache.tools.mail</div>
<h2 title="Class MailMessage" class="title">Class MailMessage</h2>
</div>
<div class="contentContainer">
<ul class="inheritance">
<li>java.lang.Object</li>
<li>
<ul class="inheritance">
<li>org.apache.tools.mail.MailMessage</li>
</ul>
</li>
</ul>
<div class="description">
<ul class="blockList">
<li class="blockList">
<hr>
<br>
<pre>public class <span class="strong">MailMessage</span>
extends java.lang.Object</pre>
<div class="block">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.
<p>
It can be used like this:
<blockquote><pre>
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();
</pre></blockquote>
<p>
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.
<p>
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.
<p>
Still to do:
<ul>
<li>Figure out how to close the connection in case of error
</ul></div>
<dl><dt><span class="strong">Version:</span></dt>
<dd>1.1, 2000/03/19, added angle brackets to address, helps some servers
version 1.0, 1999/12/29</dd></dl>
</li>
</ul>
</div>
<div class="summary">
<ul class="blockList">
<li class="blockList">
<!-- =========== FIELD SUMMARY =========== -->
<ul class="blockList">
<li class="blockList"><a name="field_summary">
<!-- -->
</a>
<h3>Field Summary</h3>
<table class="overviewSummary" border="0" cellpadding="3" cellspacing="0" summary="Field Summary table, listing fields, and an explanation">
<caption><span>Fields</span><span class="tabEnd"> </span></caption>
<tr>
<th class="colFirst" scope="col">Modifier and Type</th>
<th class="colLast" scope="col">Field and Description</th>
</tr>
<tr class="altColor">
<td class="colFirst"><code>static java.lang.String</code></td>
<td class="colLast"><code><strong><a href="../../../../org/apache/tools/mail/MailMessage.html#DEFAULT_HOST">DEFAULT_HOST</a></strong></code>
<div class="block">default mailhost</div>
</td>
</tr>
<tr class="rowColor">
<td class="colFirst"><code>static int</code></td>
<td class="colLast"><code><strong><a href="../../../../org/apache/tools/mail/MailMessage.html#DEFAULT_PORT">DEFAULT_PORT</a></strong></code>
<div class="block">default port for SMTP: 25</div>
</td>
</tr>
</table>
</li>
</ul>
<!-- ======== CONSTRUCTOR SUMMARY ======== -->
<ul class="blockList">
<li class="blockList"><a name="constructor_summary">
<!-- -->
</a>
<h3>Constructor Summary</h3>
<table class="overviewSummary" border="0" cellpadding="3" cellspacing="0" summary="Constructor Summary table, listing constructors, and an explanation">
<caption><span>Constructors</span><span class="tabEnd"> </span></caption>
<tr>
<th class="colOne" scope="col">Constructor and Description</th>
</tr>
<tr class="altColor">
<td class="colOne"><code><strong><a href="../../../../org/apache/tools/mail/MailMessage.html#MailMessage()">MailMessage</a></strong>()</code>
<div class="block">Constructs a new MailMessage to send an email.</div>
</td>
</tr>
<tr class="rowColor">
<td class="colOne"><code><strong><a href="../../../../org/apache/tools/mail/MailMessage.html#MailMessage(java.lang.String)">MailMessage</a></strong>(java.lang.String host)</code>
<div class="block">Constructs a new MailMessage to send an email.</div>
</td>
</tr>
<tr class="altColor">
<td class="colOne"><code><strong><a href="../../../../org/apache/tools/mail/MailMessage.html#MailMessage(java.lang.String, int)">MailMessage</a></strong>(java.lang.String host,
int port)</code>
<div class="block">Constructs a new MailMessage to send an email.</div>
</td>
</tr>
</table>
</li>
</ul>
<!-- ========== METHOD SUMMARY =========== -->
<ul class="blockList">
<li class="blockList"><a name="method_summary">
<!-- -->
</a>
<h3>Method Summary</h3>
<table class="overviewSummary" border="0" cellpadding="3" cellspacing="0" summary="Method Summary table, listing methods, and an explanation">
<caption><span>Methods</span><span class="tabEnd"> </span></caption>
<tr>
<th class="colFirst" scope="col">Modifier and Type</th>
<th class="colLast" scope="col">Method and Description</th>
</tr>
<tr class="altColor">
<td class="colFirst"><code>void</code></td>
<td class="colLast"><code><strong><a href="../../../../org/apache/tools/mail/MailMessage.html#bcc(java.lang.String)">bcc</a></strong>(java.lang.String bcc)</code>
<div class="block">Sets the bcc address.</div>
</td>
</tr>
<tr class="rowColor">
<td class="colFirst"><code>void</code></td>
<td class="colLast"><code><strong><a href="../../../../org/apache/tools/mail/MailMessage.html#cc(java.lang.String)">cc</a></strong>(java.lang.String cc)</code>
<div class="block">Sets the cc address.</div>
</td>
</tr>
<tr class="altColor">
<td class="colFirst"><code>void</code></td>
<td class="colLast"><code><strong><a href="../../../../org/apache/tools/mail/MailMessage.html#from(java.lang.String)">from</a></strong>(java.lang.String from)</code>
<div class="block">Sets the from address.</div>
</td>
</tr>
<tr class="rowColor">
<td class="colFirst"><code>java.io.PrintStream</code></td>
<td class="colLast"><code><strong><a href="../../../../org/apache/tools/mail/MailMessage.html#getPrintStream()">getPrintStream</a></strong>()</code>
<div class="block">Returns a PrintStream that can be used to write the body of the message.</div>
</td>
</tr>
<tr class="altColor">
<td class="colFirst"><code>void</code></td>
<td class="colLast"><code><strong><a href="../../../../org/apache/tools/mail/MailMessage.html#replyto(java.lang.String)">replyto</a></strong>(java.lang.String rto)</code>
<div class="block">Sets the replyto address
This method may be
called multiple times.</div>
</td>
</tr>
<tr class="rowColor">
<td class="colFirst"><code>void</code></td>
<td class="colLast"><code><strong><a href="../../../../org/apache/tools/mail/MailMessage.html#sendAndClose()">sendAndClose</a></strong>()</code>
<div class="block">Sends the message and closes the connection to the server.</div>
</td>
</tr>
<tr class="altColor">
<td class="colFirst"><code>void</code></td>
<td class="colLast"><code><strong><a href="../../../../org/apache/tools/mail/MailMessage.html#setHeader(java.lang.String, java.lang.String)">setHeader</a></strong>(java.lang.String name,
java.lang.String value)</code>
<div class="block">Sets the named header to the given value.</div>
</td>
</tr>
<tr class="rowColor">
<td class="colFirst"><code>void</code></td>
<td class="colLast"><code><strong><a href="../../../../org/apache/tools/mail/MailMessage.html#setPort(int)">setPort</a></strong>(int port)</code>
<div class="block">Set the port to connect to the SMTP host.</div>
</td>
</tr>
<tr class="altColor">
<td class="colFirst"><code>void</code></td>
<td class="colLast"><code><strong><a href="../../../../org/apache/tools/mail/MailMessage.html#setSubject(java.lang.String)">setSubject</a></strong>(java.lang.String subj)</code>
<div class="block">Sets the subject of the mail message.</div>
</td>
</tr>
<tr class="rowColor">
<td class="colFirst"><code>void</code></td>
<td class="colLast"><code><strong><a href="../../../../org/apache/tools/mail/MailMessage.html#to(java.lang.String)">to</a></strong>(java.lang.String to)</code>
<div class="block">Sets the to address.</div>
</td>
</tr>
</table>
<ul class="blockList">
<li class="blockList"><a name="methods_inherited_from_class_java.lang.Object">
<!-- -->
</a>
<h3>Methods inherited from class java.lang.Object</h3>
<code>clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait</code></li>
</ul>
</li>
</ul>
</li>
</ul>
</div>
<div class="details">
<ul class="blockList">
<li class="blockList">
<!-- ============ FIELD DETAIL =========== -->
<ul class="blockList">
<li class="blockList"><a name="field_detail">
<!-- -->
</a>
<h3>Field Detail</h3>
<a name="DEFAULT_HOST">
<!-- -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>DEFAULT_HOST</h4>
<pre>public static final java.lang.String DEFAULT_HOST</pre>
<div class="block">default mailhost</div>
<dl><dt><span class="strong">See Also:</span></dt><dd><a href="../../../../constant-values.html#org.apache.tools.mail.MailMessage.DEFAULT_HOST">Constant Field Values</a></dd></dl>
</li>
</ul>
<a name="DEFAULT_PORT">
<!-- -->
</a>
<ul class="blockListLast">
<li class="blockList">
<h4>DEFAULT_PORT</h4>
<pre>public static final int DEFAULT_PORT</pre>
<div class="block">default port for SMTP: 25</div>
<dl><dt><span class="strong">See Also:</span></dt><dd><a href="../../../../constant-values.html#org.apache.tools.mail.MailMessage.DEFAULT_PORT">Constant Field Values</a></dd></dl>
</li>
</ul>
</li>
</ul>
<!-- ========= CONSTRUCTOR DETAIL ======== -->
<ul class="blockList">
<li class="blockList"><a name="constructor_detail">
<!-- -->
</a>
<h3>Constructor Detail</h3>
<a name="MailMessage()">
<!-- -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>MailMessage</h4>
<pre>public MailMessage()
throws java.io.IOException</pre>
<div class="block">Constructs a new MailMessage to send an email.
Use localhost as the mail server with port 25.</div>
<dl><dt><span class="strong">Throws:</span></dt>
<dd><code>java.io.IOException</code> - if there's any problem contacting the mail server</dd></dl>
</li>
</ul>
<a name="MailMessage(java.lang.String)">
<!-- -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>MailMessage</h4>
<pre>public MailMessage(java.lang.String host)
throws java.io.IOException</pre>
<div class="block">Constructs a new MailMessage to send an email.
Use the given host as the mail server with port 25.</div>
<dl><dt><span class="strong">Parameters:</span></dt><dd><code>host</code> - the mail server to use</dd>
<dt><span class="strong">Throws:</span></dt>
<dd><code>java.io.IOException</code> - if there's any problem contacting the mail server</dd></dl>
</li>
</ul>
<a name="MailMessage(java.lang.String, int)">
<!-- -->
</a>
<ul class="blockListLast">
<li class="blockList">
<h4>MailMessage</h4>
<pre>public MailMessage(java.lang.String host,
int port)
throws java.io.IOException</pre>
<div class="block">Constructs a new MailMessage to send an email.
Use the given host and port as the mail server.</div>
<dl><dt><span class="strong">Parameters:</span></dt><dd><code>host</code> - the mail server to use</dd><dd><code>port</code> - the port to connect to</dd>
<dt><span class="strong">Throws:</span></dt>
<dd><code>java.io.IOException</code> - if there's any problem contacting the mail server</dd></dl>
</li>
</ul>
</li>
</ul>
<!-- ============ METHOD DETAIL ========== -->
<ul class="blockList">
<li class="blockList"><a name="method_detail">
<!-- -->
</a>
<h3>Method Detail</h3>
<a name="setPort(int)">
<!-- -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>setPort</h4>
<pre>public void setPort(int port)</pre>
<div class="block">Set the port to connect to the SMTP host.</div>
<dl><dt><span class="strong">Parameters:</span></dt><dd><code>port</code> - the port to use for connection.</dd><dt><span class="strong">See Also:</span></dt><dd><a href="../../../../org/apache/tools/mail/MailMessage.html#DEFAULT_PORT"><code>DEFAULT_PORT</code></a></dd></dl>
</li>
</ul>
<a name="from(java.lang.String)">
<!-- -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>from</h4>
<pre>public void from(java.lang.String from)
throws java.io.IOException</pre>
<div class="block">Sets the from address. Also sets the "From" header. This method should
be called only once.</div>
<dl><dt><span class="strong">Parameters:</span></dt><dd><code>from</code> - the from address</dd>
<dt><span class="strong">Throws:</span></dt>
<dd><code>java.io.IOException</code> - if there's any problem reported by the mail server</dd></dl>
</li>
</ul>
<a name="replyto(java.lang.String)">
<!-- -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>replyto</h4>
<pre>public void replyto(java.lang.String rto)</pre>
<div class="block">Sets the replyto address
This method may be
called multiple times.</div>
<dl><dt><span class="strong">Parameters:</span></dt><dd><code>rto</code> - the replyto address</dd></dl>
</li>
</ul>
<a name="to(java.lang.String)">
<!-- -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>to</h4>
<pre>public void to(java.lang.String to)
throws java.io.IOException</pre>
<div class="block">Sets the to address. Also sets the "To" header. This method may be
called multiple times.</div>
<dl><dt><span class="strong">Parameters:</span></dt><dd><code>to</code> - the to address</dd>
<dt><span class="strong">Throws:</span></dt>
<dd><code>java.io.IOException</code> - if there's any problem reported by the mail server</dd></dl>
</li>
</ul>
<a name="cc(java.lang.String)">
<!-- -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>cc</h4>
<pre>public void cc(java.lang.String cc)
throws java.io.IOException</pre>
<div class="block">Sets the cc address. Also sets the "Cc" header. This method may be
called multiple times.</div>
<dl><dt><span class="strong">Parameters:</span></dt><dd><code>cc</code> - the cc address</dd>
<dt><span class="strong">Throws:</span></dt>
<dd><code>java.io.IOException</code> - if there's any problem reported by the mail server</dd></dl>
</li>
</ul>
<a name="bcc(java.lang.String)">
<!-- -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>bcc</h4>
<pre>public void bcc(java.lang.String bcc)
throws java.io.IOException</pre>
<div class="block">Sets the bcc address. Does NOT set any header since it's a *blind* copy.
This method may be called multiple times.</div>
<dl><dt><span class="strong">Parameters:</span></dt><dd><code>bcc</code> - the bcc address</dd>
<dt><span class="strong">Throws:</span></dt>
<dd><code>java.io.IOException</code> - if there's any problem reported by the mail server</dd></dl>
</li>
</ul>
<a name="setSubject(java.lang.String)">
<!-- -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>setSubject</h4>
<pre>public void setSubject(java.lang.String subj)</pre>
<div class="block">Sets the subject of the mail message. Actually sets the "Subject"
header.</div>
<dl><dt><span class="strong">Parameters:</span></dt><dd><code>subj</code> - the subject of the mail message</dd></dl>
</li>
</ul>
<a name="setHeader(java.lang.String, java.lang.String)">
<!-- -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>setHeader</h4>
<pre>public void setHeader(java.lang.String name,
java.lang.String value)</pre>
<div class="block">Sets the named header to the given value. RFC 822 provides the rules for
what text may constitute a header name and value.</div>
<dl><dt><span class="strong">Parameters:</span></dt><dd><code>name</code> - name of the header</dd><dd><code>value</code> - contents of the header</dd></dl>
</li>
</ul>
<a name="getPrintStream()">
<!-- -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>getPrintStream</h4>
<pre>public java.io.PrintStream getPrintStream()
throws java.io.IOException</pre>
<div class="block">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</div>
<dl><dt><span class="strong">Returns:</span></dt><dd>a printstream containing the data and the headers of the email</dd>
<dt><span class="strong">Throws:</span></dt>
<dd><code>java.io.IOException</code> - if there's any problem reported by the mail server</dd><dt><span class="strong">See Also:</span></dt><dd><a href="../../../../org/apache/tools/ant/taskdefs/email/Message.html" title="class in org.apache.tools.ant.taskdefs.email"><code>Message</code></a></dd></dl>
</li>
</ul>
<a name="sendAndClose()">
<!-- -->
</a>
<ul class="blockListLast">
<li class="blockList">
<h4>sendAndClose</h4>
<pre>public void sendAndClose()
throws java.io.IOException</pre>
<div class="block">Sends the message and closes the connection to the server.
The MailMessage object cannot be reused.</div>
<dl><dt><span class="strong">Throws:</span></dt>
<dd><code>java.io.IOException</code> - if there's any problem reported by the mail server</dd></dl>
</li>
</ul>
</li>
</ul>
</li>
</ul>
</div>
</div>
<!-- ========= END OF CLASS DATA ========= -->
<!-- ======= START OF BOTTOM NAVBAR ====== -->
<div class="bottomNav"><a name="navbar_bottom">
<!-- -->
</a><a href="#skip-navbar_bottom" title="Skip navigation links"></a><a name="navbar_bottom_firstrow">
<!-- -->
</a>
<ul class="navList" title="Navigation">
<li><a href="../../../../overview-summary.html">Overview</a></li>
<li><a href="package-summary.html">Package</a></li>
<li class="navBarCell1Rev">Class</li>
<li><a href="package-tree.html">Tree</a></li>
<li><a href="../../../../deprecated-list.html">Deprecated</a></li>
<li><a href="../../../../index-all.html">Index</a></li>
<li><a href="../../../../help-doc.html">Help</a></li>
</ul>
</div>
<div class="subNav">
<ul class="navList">
<li><a href="../../../../org/apache/tools/mail/ErrorInQuitException.html" title="class in org.apache.tools.mail"><span class="strong">Prev Class</span></a></li>
<li><a href="../../../../org/apache/tools/mail/SmtpResponseReader.html" title="class in org.apache.tools.mail"><span class="strong">Next Class</span></a></li>
</ul>
<ul class="navList">
<li><a href="../../../../index.html?org/apache/tools/mail/MailMessage.html" target="_top">Frames</a></li>
<li><a href="MailMessage.html" target="_top">No Frames</a></li>
</ul>
<ul class="navList" id="allclasses_navbar_bottom">
<li><a href="../../../../allclasses-noframe.html">All Classes</a></li>
</ul>
<div>
<script type="text/javascript"><!--
allClassesLink = document.getElementById("allclasses_navbar_bottom");
if(window==top) {
allClassesLink.style.display = "block";
}
else {
allClassesLink.style.display = "none";
}
//-->
</script>
</div>
<div>
<ul class="subNavList">
<li>Summary: </li>
<li>Nested | </li>
<li><a href="#field_summary">Field</a> | </li>
<li><a href="#constructor_summary">Constr</a> | </li>
<li><a href="#method_summary">Method</a></li>
</ul>
<ul class="subNavList">
<li>Detail: </li>
<li><a href="#field_detail">Field</a> | </li>
<li><a href="#constructor_detail">Constr</a> | </li>
<li><a href="#method_detail">Method</a></li>
</ul>
</div>
<a name="skip-navbar_bottom">
<!-- -->
</a></div>
<!-- ======== END OF BOTTOM NAVBAR ======= -->
</body>
</html>