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

事情是这样的

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

1. 如何生成文件?

2.如果将生成的文件加载到Ant里面?

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

邮件内容放在 content.template里面  

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

在Ant里加上如下代码:

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

然后再发送邮件

<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.):

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

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的功劳了

转载于:https://my.oschina.net/u/134516/blog/151299

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值