aboutsummaryrefslogtreecommitdiffstats
path: root/framework/src/ant/apache-ant-1.9.6/manual/Tasks/mail.html
blob: b59633d6237543011fb0cb1eef7f392e002d3d33 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
<!--
   Licensed to the Apache Software Foundation (ASF) under one or more
   contributor license agreements.  See the NOTICE file distributed with
   this work for additional information regarding copyright ownership.
   The ASF licenses this file to You under the Apache License, Version 2.0
   (the "License"); you may not use this file except in compliance with
   the License.  You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
-->
<html>

<head>
<meta http-equiv="Content-Language" content="en-us">
<link rel="stylesheet" type="text/css" href="../stylesheets/style.css">
<title>Mail Task</title>
</head>

<body>

<h2><a name="mail">Mail</a></h2>
<h3>Description</h3>
  <p>
    A task to send SMTP email.
  </p>
  <p>
    This task can send mail using either plain
    text, UU encoding, or MIME format mail, depending on what is available.
  </p>
  <p>
    SMTP auth and SSL/TLS require JavaMail and are only available in MIME format.
  </p>
  <p>
    Attachments may be sent using nested
    <code>&lt;attachments&gt;</code> elements, which are <a
    href="../using.html#path">path-like structures</a>.  This means
    any filesystem based <a
    href="../Types/resources.html">resource</a> or resource
    collection can be used to point to attachments.  Prior to Apache Ant 1.7
    only <code>&lt;fileset&gt;</code> has been supported as a nested
    element, you can still use this directly without an
    <code>&lt;attachments&gt;</code> container.
  </p>
  <p>
    <strong>Note:</strong> This task may depend on external libraries
    that are not included in the Ant distribution. 
    See <a href="../install.html#librarydependencies">Library Dependencies</a>
    for more information.
  </p>

<h3>Parameters</h3>
<table border="1" cellpadding="2" cellspacing="0">
  <tr>
    <td valign="top"><b>Attribute</b></td>
    <td valign="top"><b>Description</b></td>
    <td align="center" valign="top"><b>Required</b></td>
  </tr>
  <tr>
    <td valign="top">from</td>
    <td valign="top">Email address of sender.</td>
    <td align="center" valign="top">Either a <code>from</code> attribute, or a <code>&lt;from&gt;</code>
    element.</td>
  </tr>
  <tr>
    <td valign="top">replyto</td>
    <td valign="top">Replyto email address.</td>
    <td align="center" valign="top">No</td>
  </tr>
  <tr>
    <td valign="top">tolist</td>
    <td valign="top">Comma-separated list of recipients.</td>
    <td align="center" valign="middle" rowspan="3">At least one of these, or the
       equivalent elements.</td>
  </tr>
  <tr>
    <td valign="top">cclist</td>
    <td valign="top">Comma-separated list of recipients to carbon copy</td>
    </tr>
  <tr>
    <td valign="top">bcclist</td>
    <td valign="top">Comma-separated list of recipients to blind carbon copy
    </td>
  </tr>
  <tr>
    <td valign="top">message</td>
    <td valign="top">Message to send in the body of the email.</td>
    <td align="center" valign="middle" rowspan="2">One of these or a
    <code>&lt;message&gt;</code> element.</td>
  </tr>
  <tr>
    <td valign="top">messagefile</td>
    <td valign="top">File to send as the body of the email. Property
    values in the file will be expanded.</td>
  </tr>
  <tr>
    <td valign="top">messagefileinputencoding</td>
    <td valign="top">
      Specifies the encoding of the input file. Please see
      <a href="http://docs.oracle.com/javase/7/docs/technotes/guides/intl/encoding.doc.html">
        Supported Encodings</a> for a list of possible
      values. Defaults to the platform's default character
      encoding. <em>Since Ant 1.9.4</em>
    </td>
    <td valign="top" align="center">No</td>
  </tr>
  <tr>
    <td valign="top">messagemimetype</td>
    <td valign="top">The content type of the message.  The default is
    <code>text/plain</code>.</td>
    <td align="center" valign="top">No</td>
  </tr>
  <tr>
    <td valign="top">files</td>
    <td valign="top">Files to send as attachments to the email.  Separate multiple
    file names using a comma or space.  You can also use <code>&lt;fileset&gt;</code>
    elements to specify files.</td>
    <td align="center" valign="top">No</td>
  </tr>
  <tr>
    <td valign="top">failonerror</td>
    <td valign="top">flag to indicate whether to halt the build on
    any error.  The default value is <code>true</code>.</td>
    <td align="center" valign="top">No.</td>
  </tr>
  <tr>
    <td valign="top">includefilenames</td>
    <td valign="top">Include filename(s) before file contents.
    Valid only when the <code>plain</code> encoding is used.  The default
    value is <code>false</code>.</td>
    <td align="center" valign="top">No</td>
  </tr>
  <tr>
    <td valign="top">mailhost</td>
    <td valign="top">Host name of the SMTP server.  The default value is
    <code>localhost</code>.</td>
    <td align="center" valign="top">No</td>
  </tr>
  <tr>
    <td valign="top">mailport</td>
    <td valign="top">TCP port of the SMTP server.  The default value is 25.</td>
    <td align="center" valign="top">No</td>
  </tr>
  <tr>
    <td valign="top">user</td>
    <td valign="top">user name for SMTP auth</td>
    <td valign="center">Yes, if SMTP auth is required on your SMTP server<br></br>
    the email message will be then sent using Mime and requires JavaMail</td>
  </tr>
  <tr>
    <td valign="top">password</td>
    <td valign="top">password for SMTP auth</td>
    <td valign="center">Yes, if SMTP auth is required on your SMTP server<br></br>
    the email message will be then sent using Mime and requires JavaMail</td>
  </tr>
  <tr>
    <td valign="top">ssl</td>
    <td valign="top">"true", "on" or "yes" accepted here<br></br>
    indicates whether you need TLS/SSL</td>
    <td align="center" valign="top">No</td>
  </tr>
  <tr>
    <td valign="top">encoding</td>
    <td valign="top">Specifies the encoding to use for the content of the email.
    Values are <code>mime</code>, <code>uu</code>, <code>plain</code>, or
      <code>auto</code>.  The default value is <code>auto</code>.
      <code>uu</code> or <code>plain</code> are not compatible with SMTP auth</td>
    <td align="center" valign="top">No</td>
  </tr>
  <tr>
    <td valign="top">charset</td>
    <td valign="top">Character set of the email.<br>
    You can also set the charset in the message nested element.<br>
    These options are mutually exclusive.</td>
    <td align="center" valign="top">No</td>
  </tr>
  <tr>
    <td valign="top">subject</td>
    <td valign="top">Email subject line.</td>
    <td align="center" valign="top">No</td>
  </tr>
  <tr>
    <td valign="top">ignoreInvalidRecipients</td>
    <td valign="top">Boolean.  Whether the task should try to send
      the message to as many recipients as possible and should only
      fail if neither is reachable.  <em>Since Ant 1.8.0</em>.</td>
    <td align="center" valign="top">No, default is false</td>
  </tr>
  <tr>
    <td valign="top">enableStartTLS</td>
    <td valign="top">"true", "on" or "yes" accepted here<br></br>
      whether the STARTTLS command used to switch to an encrypted
      connection for authentication should be supported.  Requires
      JavaMail.  <em>Since Ant 1.8.0</em></td>
    <td align="center" valign="top">No</td>
  </tr>
</table>

<h3>Note regarding the attributes containing email addresses</h3>
Since Ant 1.6, the attributes from, replyto, tolist, cclist, bcclist
can contain email addresses of the form :
<ul>
<li>address@xyz.com</li>
<li>name &lt;address@xyz.com&gt;</li>
<li>&lt;address@xyz.com&gt; name</li>
<li>(name) address@xyz.com</li>
<li>address@xyz.com (name)</li>
</ul>
<p>You need to enter the angle brackets as XML entities
<code>&amp;gt;</code> and <code>&amp;lt;</code>.</p>

<h3>Parameters specified as nested elements</h3>

<h4>to / cc / bcc / from/ replyto </h4>
<p>Adds an email address element.  It takes the following attributes:</p>

<table width="60%" border="1" cellpadding="2" cellspacing="0">
  <tr>
    <td valign="top"><b>Attribute</b></td>
    <td valign="top"><b>Description</b></td>
    <td align="center" valign="top"><b>Required</b></td>
  </tr>
  <tr>
    <td valign="top">name</td>
    <td valign="top">The display name for the address.</td>
    <td align="center" valign="top">No</td>
  </tr>
  <tr>
    <td valign="top">address</td>
    <td valign="top">The email address.</td>
    <td align="center" valign="top">Yes</td>
  </tr>
</table>

<h4>message</h4>

<p>Specifies the message to include in the email body.  It takes the following
attributes:</p>

<table width="60%" border="1" cellpadding="2" cellspacing="0">
  <tr>
    <td valign="top"><b>Attribute</b></td>
    <td valign="top"><b>Description</b></td>
    <td align="center" valign="top"><b>Required</b></td>
  </tr>
  <tr>
    <td valign="top">src</td>
    <td valign="top">The file to use as the message.</td>
    <td align="center" valign="top">No</td>
  </tr>
  <tr>
    <td valign="top">mimetype</td>
    <td valign="top">The content type to use for the message.</td>
    <td align="center" valign="top">No</td>
  </tr>
  <tr>
    <td valign="top">charset</td>
    <td valign="top">Character set of the message<br>
    You can also set the charset as attribute of the enclosing mail task.<br>
    These options are mutually exclusive.</td>
    <td align="center" valign="top">No</td>
  </tr>
  <tr>
    <td valign="top">inputencoding</td>
    <td valign="top">
      Specifies the encoding of the input file. Please see
      <a href="http://docs.oracle.com/javase/7/docs/technotes/guides/intl/encoding.doc.html">
        Supported Encodings</a> for a list of possible
      values. Defaults to the platform's default character
      encoding. <em>Since Ant 1.9.4</em>
    </td>
    <td valign="top" align="center">No</td>
  </tr>
</table>

<p>If the <code>src</code> attribute is not specified, then text can be added
inside the <code>&lt;message&gt;</code> element. Property expansion will occur
in the message, whether it is specified as an external file or as text within
the <code>&lt;message&gt;</code> element.</p>

<h4>header</h4>
<p><strong>Since Ant 1.7</strong>, arbitrary mail headers can be added by
  specifying these attributes on one or more nested header elements:</p>

<table width="60%" border="1" cellpadding="2" cellspacing="0">
  <tr>
    <td valign="top"><b>Attribute</b></td>
    <td valign="top"><b>Description</b></td>
    <td align="center" valign="top"><b>Required</b></td>
  </tr>
  <tr>
    <td valign="top">name</td>
    <td valign="top">The name associated with this mail header.</td>
    <td align="center" valign="top">Yes</td>
  </tr>
  <tr>
    <td valign="top">value</td>
    <td valign="top">The value to assign to this mail header.</td>
    <td align="center" valign="top">Yes</td>
  </tr>
</table>

<p>It is permissible to duplicate the name attribute amongst multiple headers.
</p>

<h3>Examples</h3>

<blockquote><pre>
&lt;mail from=&quot;me&quot;
      tolist=&quot;you&quot;
      subject=&quot;Results of nightly build&quot;
      files=&quot;build.log&quot;/&gt;
</pre></blockquote>

<p>Sends an email from <i>me</i> to <i>you</i> with a subject of
<i>Results of nightly build</i> and includes the contents of the file
<i>build.log</i> in the body of the message.</p>

<blockquote><pre>
&lt;mail mailhost=&quot;smtp.myisp.com&quot; mailport=&quot;1025&quot; subject=&quot;Test build&quot;&gt;
  &lt;from address=&quot;config@myisp.com&quot;/&gt;
  &lt;replyto address=&quot;me@myisp.com&quot;/&gt;
  &lt;to address=&quot;all@xyz.com&quot;/&gt;
  &lt;message&gt;The ${buildname} nightly build has completed&lt;/message&gt;
  &lt;attachments&gt;
    &lt;fileset dir=&quot;dist&quot;&gt;
      &lt;include name=&quot;**/*.zip&quot;/&gt;
    &lt;/fileset&gt;
  &lt;/attachments&gt;
&lt;/mail&gt;
</pre></blockquote>

<p>Sends an eMail from <i>config@myisp.com</i> to <i>all@xyz.com</i> with a subject of
<i>Test Build</i>. Replies to this email will go to <i>me@myisp.com</i>.
Any zip files from the dist directory are attached.&nbsp; The
task will attempt to use JavaMail and fall back to UU encoding or no encoding in
that order depending on what support classes are available. <code>${buildname}</code>
will be replaced with the <code>buildname</code> property's value.</p>

<blockquote><pre>
&lt;property name=&quot;line2&quot; value=&quot;some_international_message&quot;/&gt;
&lt;echo message=&quot;${line2}&quot;/&gt;

&lt;mail mailhost=&quot;somehost@xyz.com&quot; mailport=&quot;25&quot; subject=&quot;Test build&quot;  charset=&quot;utf-8&quot;&gt;
  &lt;from address=&quot;me@myist.com&quot;/&gt;
  &lt;to address=&quot;all@xyz.com&quot;/&gt;
  &lt;message&gt;some international text:${line2}&lt;/message&gt;
&lt;/mail&gt;
</pre></blockquote>

<p>Sends an eMail from <i>me@myisp.com</i> to <i>all@xyz.com</i> with a subject of
<i>Test Build</i>, the message body being coded in UTF-8



</body>
</html>