You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

mail.html 11 KiB

3 years ago
3 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  1. <!DOCTYPE html>
  2. <!--
  3. Licensed to the Apache Software Foundation (ASF) under one or more
  4. contributor license agreements. See the NOTICE file distributed with
  5. this work for additional information regarding copyright ownership.
  6. The ASF licenses this file to You under the Apache License, Version 2.0
  7. (the "License"); you may not use this file except in compliance with
  8. the License. You may obtain a copy of the License at
  9. https://www.apache.org/licenses/LICENSE-2.0
  10. Unless required by applicable law or agreed to in writing, software
  11. distributed under the License is distributed on an "AS IS" BASIS,
  12. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. See the License for the specific language governing permissions and
  14. limitations under the License.
  15. -->
  16. <html lang="en">
  17. <head>
  18. <link rel="stylesheet" type="text/css" href="../stylesheets/style.css">
  19. <title>Mail Task</title>
  20. </head>
  21. <body>
  22. <h2 id="mail">Mail</h2>
  23. <h3>Description</h3>
  24. <p>A task to send SMTP email.</p>
  25. <p>This task can send mail using either plain text, UU encoding, or MIME format mail, depending on
  26. what is available.</p>
  27. <p>SMTP auth and SSL/TLS require JavaMail or JakartaMail and are only available in MIME format.</p>
  28. <p>Attachments may be sent using nested <code>&lt;attachments&gt;</code> elements, which
  29. are <a href="../using.html#path">path-like structures</a>. This means any filesystem
  30. based <a href="../Types/resources.html">resource</a> or resource collection can be used to point to
  31. attachments. Prior to Apache Ant 1.7 only <code>&lt;fileset&gt;</code> has been supported as a
  32. nested element, you can still use this directly without an <code>&lt;attachments&gt;</code>
  33. container.</p>
  34. <p><strong>Note</strong>: This task may depend on external libraries that are not included in the
  35. Ant distribution. See <a href="../install.html#librarydependencies">Library Dependencies</a> for
  36. more information.</p>
  37. <p>Starting with Ant 1.10.13 Ant supports either the modern <code>jakarta.mail</code> as well as the
  38. older <code>javax.mail</code> implementations and will prefer <code>jakarta.mail</code> if both are available.</p>
  39. <h3>Parameters</h3>
  40. <table class="attr">
  41. <tr>
  42. <th scope="col">Attribute</th>
  43. <th scope="col">Description</th>
  44. <th scope="col">Required</th>
  45. </tr>
  46. <tr>
  47. <td>from</td>
  48. <td>Email address of sender.</td>
  49. <td>Either a <var>from</var> attribute, or a <code>&lt;from&gt;</code> element.</td>
  50. </tr>
  51. <tr>
  52. <td>replyto</td>
  53. <td>Reply-to email address.</td>
  54. <td>No</td>
  55. </tr>
  56. <tr>
  57. <td>tolist</td>
  58. <td>Comma-separated list of recipients.</td>
  59. <td rowspan="3">At least one of these, or the equivalent nested elements</td>
  60. </tr>
  61. <tr>
  62. <td>cclist</td>
  63. <td class="left">Comma-separated list of recipients to carbon copy</td>
  64. </tr>
  65. <tr>
  66. <td>bcclist</td>
  67. <td class="left">Comma-separated list of recipients to blind carbon copy
  68. </td>
  69. </tr>
  70. <tr>
  71. <td>message</td>
  72. <td>Message to send in the body of the email.</td>
  73. <td rowspan="2">One of these or a <code>&lt;message&gt;</code> element.</td>
  74. </tr>
  75. <tr>
  76. <td>messagefile</td>
  77. <td class="left">File to send as the body of the email. Property values in the file will be
  78. expanded.</td>
  79. </tr>
  80. <tr>
  81. <td>messagefileinputencoding</td>
  82. <td>Specifies the encoding of the input file. Please
  83. see <a href="https://docs.oracle.com/javase/8/docs/technotes/guides/intl/encoding.doc.html"
  84. target="_top">Supported Encodings</a> for a list of possible values. <em>Since Ant 1.9.4</em>
  85. </td>
  86. <td>No; defaults to default JVM character encoding</td>
  87. </tr>
  88. <tr>
  89. <td>messagemimetype</td>
  90. <td>The content type of the message.</td>
  91. <td>No; default is <q>text/plain</q></td>
  92. </tr>
  93. <tr>
  94. <td>files</td>
  95. <td>Files to send as attachments to the email. Separate multiple file names using a comma or
  96. space. You can also use <code>&lt;fileset&gt;</code> elements to specify files.</td>
  97. <td>No</td>
  98. </tr>
  99. <tr>
  100. <td>failonerror</td>
  101. <td>flag to indicate whether to halt the build on any error.</td>
  102. <td>No; default is <q>true</q></td>
  103. </tr>
  104. <tr>
  105. <td>includefilenames</td>
  106. <td>Include filename(s) before file contents.</td>
  107. <td>No; default is <q>false</q>, ignored unless <q>plain</q> encoding is used</td>
  108. </tr>
  109. <tr>
  110. <td>mailhost</td>
  111. <td>Host name of the SMTP server.</td>
  112. <td>No; default is <q>localhost</q></td>
  113. </tr>
  114. <tr>
  115. <td>mailport</td>
  116. <td>TCP port of the SMTP server.</td>
  117. <td>No; default is <q>25</q></td>
  118. </tr>
  119. <tr>
  120. <td>user</td>
  121. <td>user name for SMTP auth</td>
  122. <td>Yes, if SMTP auth is required on your SMTP server;<br/>the email message will be then sent
  123. using MIME and requires JavaMail</td>
  124. </tr>
  125. <tr>
  126. <td>password</td>
  127. <td>password for SMTP auth</td>
  128. <td>Yes, if SMTP auth is required on your SMTP server;<br/>the email message will be then sent
  129. using MIME and requires JavaMail</td>
  130. </tr>
  131. <tr>
  132. <td>ssl</td>
  133. <td><q>true</q>, <q>on</q>, or <q>yes</q> accepted here<br/>indicates whether you need
  134. TLS/SSL</td>
  135. <td>No</td>
  136. </tr>
  137. <tr>
  138. <td>encoding</td>
  139. <td>Specifies the encoding to use for the content of the email. Values
  140. are <q>mime</q>, <q>uu</q>, <q>plain</q>, or <q>auto</q>. <q>uu</q> or <q>plain</q> are not
  141. compatible with SMTP auth</td>
  142. <td>No; default is <q>auto</q></td>
  143. </tr>
  144. <tr>
  145. <td>charset</td>
  146. <td>Character set of the email.<br/>You can also set the <var>charset</var> in
  147. the <code>message</code> nested element.<br/> These options are mutually exclusive.</td>
  148. <td>No</td>
  149. </tr>
  150. <tr>
  151. <td>subject</td>
  152. <td>Email subject line.</td>
  153. <td>No</td>
  154. </tr>
  155. <tr>
  156. <td>ignoreInvalidRecipients</td>
  157. <td>(boolean) Whether the task should try to send the message to as many recipients as possible
  158. and should only fail if neither is reachable. <em>Since Ant 1.8.0</em>.</td>
  159. <td>No; default is <q>false</q></td>
  160. </tr>
  161. <tr>
  162. <td>enableStartTLS</td>
  163. <td>(boolean) Whether the <code>STARTTLS</code> command used to switch to an encrypted
  164. connection for authentication should be supported. Requires JavaMail. <em>Since Ant
  165. 1.8.0</em></td>
  166. <td>No</td>
  167. </tr>
  168. </table>
  169. <h3>Note regarding the attributes containing email addresses</h3>
  170. <p><em>Since Ant 1.6</em>, the
  171. attributes <var>from</var>, <var>replyto</var>, <var>tolist</var>, <var>cclist</var>, <var>bcclist</var>
  172. can contain email addresses of the form:</p>
  173. <ul>
  174. <li><samp>address@xyz.com</samp></li>
  175. <li><samp>name &lt;address@xyz.com&gt;</samp></li>
  176. <li><samp>&lt;address@xyz.com&gt; name</samp></li>
  177. <li><samp>(name) address@xyz.com</samp></li>
  178. <li><samp>address@xyz.com (name)</samp></li>
  179. </ul>
  180. <p>You need to enter the angle brackets as XML entities <q>&amp;gt;</q> and <q>&amp;lt;</q>.</p>
  181. <h3>Parameters specified as nested elements</h3>
  182. <h4>to / cc / bcc / from/ replyto</h4>
  183. <p>Adds an email address element. It takes the following attributes:</p>
  184. <table class="attr">
  185. <tr>
  186. <th scope="col">Attribute</th>
  187. <th scope="col">Description</th>
  188. <th scope="col">Required</th>
  189. </tr>
  190. <tr>
  191. <td>name</td>
  192. <td>The display name for the address.</td>
  193. <td>No</td>
  194. </tr>
  195. <tr>
  196. <td>address</td>
  197. <td>The email address.</td>
  198. <td>Yes</td>
  199. </tr>
  200. </table>
  201. <h4>message</h4>
  202. <p>Specifies the message to include in the email body. It takes the following attributes:</p>
  203. <table class="attr">
  204. <tr>
  205. <th scope="col">Attribute</th>
  206. <th scope="col">Description</th>
  207. <th scope="col">Required</th>
  208. </tr>
  209. <tr>
  210. <td>src</td>
  211. <td>The file to use as the message.</td>
  212. <td>No</td>
  213. </tr>
  214. <tr>
  215. <td>mimetype</td>
  216. <td>The content type to use for the message.</td>
  217. <td>No</td>
  218. </tr>
  219. <tr>
  220. <td>charset</td>
  221. <td>Character set of the message<br/>You can also set the <var>charset</var> as attribute of the
  222. enclosing <code>mail</code> task.<br/> These options are mutually exclusive.</td>
  223. <td>No</td>
  224. </tr>
  225. <tr>
  226. <td>inputencoding</td>
  227. <td>
  228. Specifies the encoding of the input file. Please
  229. see <a href="https://docs.oracle.com/javase/8/docs/technotes/guides/intl/encoding.doc.html"
  230. target="_top">Supported Encodings</a> for a list of possible values. <em>Since Ant 1.9.4</em>
  231. </td>
  232. <td>No; defaults to default JVM character encoding</td>
  233. </tr>
  234. </table>
  235. <p>If the <var>src</var> attribute is not specified, then text can be added inside
  236. the <code>&lt;message&gt;</code> element. Property expansion will occur in the message, whether it
  237. is specified as an external file or as text within the <code>&lt;message&gt;</code> element.</p>
  238. <h4>header</h4>
  239. <p><em>Since Ant 1.7</em>, arbitrary mail headers can be added by specifying these attributes on one
  240. or more nested header elements:</p>
  241. <table class="attr">
  242. <tr>
  243. <th scope="col">Attribute</th>
  244. <th scope="col">Description</th>
  245. <th scope="col">Required</th>
  246. </tr>
  247. <tr>
  248. <td>name</td>
  249. <td>The name associated with this mail header.</td>
  250. <td>Yes</td>
  251. </tr>
  252. <tr>
  253. <td>value</td>
  254. <td>The value to assign to this mail header.</td>
  255. <td>Yes</td>
  256. </tr>
  257. </table>
  258. <p>It is permissible to duplicate the name attribute amongst multiple headers.</p>
  259. <h3>Examples</h3>
  260. <p>Send an email from <q>me</q> to <q>you</q> with a subject of <q>Results of nightly build</q> and
  261. include the contents of the file <samp>build.log</samp> in the body of the message.</p>
  262. <pre>
  263. &lt;mail from=&quot;me&quot;
  264. tolist=&quot;you&quot;
  265. subject=&quot;Results of nightly build&quot;
  266. files=&quot;build.log&quot;/&gt;</pre>
  267. <p>Send an email from <q>config@myisp.com</q> to <q>all@xyz.com</q> with a subject of <q>Test
  268. Build</q>. Replies to this email will go to <q>me@myisp.com</q>. Any zip files from
  269. the <samp>dist</samp> directory are attached. The task will attempt to use JavaMail and fall back to
  270. UU encoding or no encoding in that order depending on what support classes are
  271. available. <samp>${buildname}</samp> will be replaced with the <code>buildname</code> property's
  272. value.</p>
  273. <pre>
  274. &lt;mail mailhost=&quot;smtp.myisp.com&quot; mailport=&quot;1025&quot; subject=&quot;Test build&quot;&gt;
  275. &lt;from address=&quot;config@myisp.com&quot;/&gt;
  276. &lt;replyto address=&quot;me@myisp.com&quot;/&gt;
  277. &lt;to address=&quot;all@xyz.com&quot;/&gt;
  278. &lt;message&gt;The ${buildname} nightly build has completed&lt;/message&gt;
  279. &lt;attachments&gt;
  280. &lt;fileset dir=&quot;dist&quot;&gt;
  281. &lt;include name=&quot;**/*.zip&quot;/&gt;
  282. &lt;/fileset&gt;
  283. &lt;/attachments&gt;
  284. &lt;/mail&gt;</pre>
  285. <p>Send an email from <q>me@myisp.com</q> to <q>all@xyz.com</q> with a subject of <q>Test Build</q>,
  286. the message body being coded in UTF-8.
  287. <pre>
  288. &lt;property name=&quot;line2&quot; value=&quot;some_international_message&quot;/&gt;
  289. &lt;echo message=&quot;${line2}&quot;/&gt;
  290. &lt;mail mailhost=&quot;somehost@xyz.com&quot; mailport=&quot;25&quot; subject=&quot;Test build&quot; charset=&quot;utf-8&quot;&gt;
  291. &lt;from address=&quot;me@myist.com&quot;/&gt;
  292. &lt;to address=&quot;all@xyz.com&quot;/&gt;
  293. &lt;message&gt;some international text:${line2}&lt;/message&gt;
  294. &lt;/mail&gt;</pre>
  295. </body>
  296. </html>