Ant Mail:用一个Template文件作为邮件内容
2013-08-08 00:00
337 查看
事情是这样的
我要用Ant发送邮件,但是邮件内容是会动态变化的,每次可能不一样,这样子,我需要用过一个脚本动态生成邮件内容文件,有两个问题要解决:
1. 如何生成文件?
2.如果将生成的文件加载到Ant里面?
首先我找到了解决第二个问题的方法,就是使用Ant的LoadFile task,实现如下:
邮件内容放在 content.template里面
在Ant里加上如下代码:
然后再发送邮件
另外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文件:
而将${weather}替换为rain,则就是expandproperties的功劳了
我要用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的功劳了
相关文章推荐
- Powershell Mail module, 发送outbox 里的所有邮件(一个.csv文件代表一封邮件)
- Powershell Mail module, 发送outbox 里的全部邮件(一个.csv文件代表一封邮件)
- 一个简单的ant的build.xml文件包含的内容
- 接收一个文件内容,通过读取开始和结束标志,分别将其内容保存到不同的文件中
- day20打印流,删除一个带内容的目录,用于记录应用程序运行次数,多个读取流变成一个读取流,切割文件
- Android使用UncaughtExceptionHandler捕获全局异常 android获取手机信息大全Java追加文件内容使用JavaMail发送邮件OkHttp获取系统时间
- android 将图片内容解析成字节数组,将字节数组转换为ImageView可调用的Bitmap对象,图片缩放,把字节数组保存为一个文件,把Bitmap转Byte
- 一个简单的基于postfix+extmail+mysql的邮件系统
- 用户上传本地磁盘中的一个图片文件作为头像
- $.get获取一个文件的内容示例代码
- 一个python的邮件发送脚本,自动,定时,可以附件发送,抄送,附有说明文件
- 复制一个空洞文件且忽略掉其空洞内容
- 一个带采集远程文章内容,保存图片,生成文件等完整的采集功能
- 【第三篇日记】C#解析XML文档和excel文档(弄GoogleEarth时遇到的一个问题,作为一个初学者就大补XML的内容)
- 一个python的邮件发送脚本,自动,定时,可以附件发送,抄送,附有说明文件
- c#将一个文件夹及其里面的所有内容(文件和文件夹)复制到指定路径
- 将一个文件的内容写入到另一个文件中(字节流)
- Ant 打包war 生成文件内容build.xml
- Python 读取文件替换其中的内容并输出到一个新的文件内