Ant Mail:用一个Template文件做为邮件内容

事情是这样的 html

我要用Ant发送邮件,可是邮件内容是会动态变化的,每次可能不同,这样子,我须要用过一个脚本动态生成邮件内容文件,有两个问题要解决: java

1. 如何生成文件? apache

2.若是将生成的文件加载到Ant里面? 测试

首先我找到了解决第二个问题的方法,就是使用Ant的LoadFile task,实现以下: ui

邮件内容放在 content.template里面   spa

GENERAL INFO
BUILD 
Build URL: 
Project: 
Date of build: 
Build duration:

在Ant里加上以下代码: code

<loadfile property="email_content" srcFile="./content.template"/>

而后再发送邮件 orm

<mail 
    mailhost="${mail_server}" 
    subject="${mail_subject}" 
    cclist="${mail_distribution}" 
    ignoreInvalidRecipients="true" 
    messagemimetype="text/html">
   <from address="${mail_fromaddress}" />
   <replyto address="${mail_replyto}" />
   <message>${email_content}</message>
     <attachments>
	<fileset dir="${doc_dir_release}">
		<include name="${content_list_file_xml}" />
		<include name="${content_list_file_html}" />
	</fileset>
     </attachments>
</mail>
应就能够了,不过尚未测试验证。


另外Filterchain 能够实现将目标文件中的动态参数以property替换(f the data contains data that represents Ant properties (of the form ${...}), that is substituted with the property's actual value.): server

如文件loadfile1.tmp 里面内容为All these moments will be lost in time, like tear drops in the ${weather} xml

Ant文件:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project name="test" default="test">
  <target name="test">
	<property name="weather" value="rain" />
	<loadfile property="modifiedmessage" srcFile="./loadfile1.tmp">
		<filterchain>
			<expandproperties />
		</filterchain>
	</loadfile>
	<echo message="---+${modifiedmessage}" />
  </target>
</project>
输出为: [echo] ---+All these moments will be lost in time, like tear drops in the rain

而将${weather}替换为rain,则就是expandproperties的功劳了

相关文章
相关标签/搜索