您的位置:首页 > 大数据 > 人工智能

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

2013-08-08 00:00 337 查看
事情是这样的

我要用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的功劳了
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐