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

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