用ANT来实现邮件发送

ANT来实现邮件发送

 

下面是我用ANT来实现邮件发送的代码:

ContractedBlock.gif ExpandedBlockStart.gif Code
<?xml version = "1.0" encoding = "utf-8"?>
<project default = "sendmail">
<target name = "sendmail" description = "send mail">
       
<mail mailhost="smtp.126.com" mailport="25" subject="The Build Test" user="×××" password="***"> 
           
<from address=***@126.com name="Wentao Sun" />    
           
<to address=***@126.com name="Wentao Sun" />    
           
<message>Send email by ANT ! </message>    
       
</mail>  
</target>
</project>

 

 

ContractedBlock.gif ExpandedBlockStart.gif Code
 1 <?xml version="1.0"?>    
 2 <project name="springproj" basedir="." default="mail">    
 3     <property name="pro.name" value="springproj" />    
 4     <property name="pro.author" value="Danlley Wei" />    
 5     <property name="src.dir" value="src/main/java" />    
 6     <property name="pro.web.root" value="war" />    
 7     <property name="pro.web.source" value="${pro.web.root}/WEB-INF" />    
 8     <property name="pro.build.path" value="${pro.web.source}/classes" />    
 9     <property name="user.dir" value="${pro.build.path}" />    
10     <target name="mail" depends="mkzip">    
11        <mail mailhost="smtp.126.com" mailport="25" subject="The Build Test" user="用户名" password="邮箱密码">    
12            <from address="发送地址" name="Danlley Wei" />    
13            <fileset dir="report/html">    
14               <include name="**/test-result${ant.project.name}.zip" />    
15            </fileset>    
16            <to address="邮件接收地址" name="Danlley Wei" />    
17            <message>The ${pro.name}--${pro.author} has been tested ! </message>    
18        </mail>    
19     </target>    
20     <target name="mkzip" depends="report">    
21         <jar destfile="report/html/test-result${ant.project.name}.zip">    
22            <fileset dir="report/html">    
23               <include name="**/*.html" />    
24               <include name="**/*.css" />    
25               <include name="**/*.txt" />    
26            </fileset>    
27         </jar>    
28     </target>    
29     <target name="report" depends="junit">    
30        <junitreport id="myJUnitReport" taskname="reported" todir="report" description="Junit Report">    
31            <fileset dir="report">    
32               <include name="TEST-*.xml" />    
33            </fileset>    
34            <report todir="report/html" />    
35        </junitreport>    
36     </target>    
37     <target name="junit" depends="build">    
38        <mkdir dir="report/html" />    
39        <junit printsummary="yes" haltonerror="yes" haltonfailure="yes" fork="yes">    
40            <formatter type="plain" usefile="false" />    
41            <formatter type="xml" />    
42            <test name="org.danlley.hibernate.dao.DeptDAOImplTest" todir="report" />    
43            <classpath refid="master-classpath" />    
44        </junit>    
45     </target>    
46     <target name="build" depends="prepare">    
47        <javac destdir="${pro.build.path}" target="1.5">    
48            <src path="${src.dir}" />    
49            <classpath refid="master-classpath" />    
50        </javac>    
51        <javac destdir="${pro.build.path}" target="1.5">    
52            <src path="src/main/test" />    
53            <classpath refid="master-classpath" />    
54        </javac>    
55     </target>    
56     <target name="prepare" depends="clean">    
57        <copy todir="${pro.build.path}">    
58            <fileset dir="${src.dir}">    
59               <include name="**/*.properties" />    
60               <include name="**/*.xml" />    
61            </fileset>    
62        </copy>    
63     </target>    
64     <target name="clean">    
65        <delete>    
66            <fileset dir="${pro.build.path}">    
67               <include name="**/*.*" />    
68            </fileset>    
69            <fileset dir="report">    
70               <include name="**/*.*" />    
71            </fileset>    
72        </delete>    
73     </target>    
74     <path id="master-classpath">    
75        <fileset dir="lib">    
76            <include name="*.jar" />    
77        </fileset>    
78        <pathelement path="${pro.build.path}" />    
79     </path>    
80 </project>   
81 

 

target依赖关系:
mail→mkzip→report→junit→build→prepare→clean

工程classpath:master-classpath

clean节点:
删除测试和编译过程中生成的所有文件
prepare节点:
将工程编译打包所需资源文件全部拷贝到编译路径下
build节点:
生成工程源文件和测试代码源文件的二进制版本
junit节点:
运行测试用例
report节点:
生成测试报告
mkzip节点:
将生成的测试报告以zip格式进行打包
mail节点:
将测试结果发送到开发小组邮箱 

 

1. 我在模板 中使用的126邮箱,如果你的邮箱是新申请的126邮箱,上述模板可能没办法发送你的,原因是126邮箱对于新申请的用户暂时不开通smtp和pop3服务
2.并不会自带安装发送所需相关资源包,因此需要我们手动到sun官方网站下载,然后把资源包放到的lib下面,我的位置是:D:\apache--1.7.0\lib
可以从下面地址下载所需的两个资源(mail.jar和activation.jar):
http://java.sun.com/products/javamail
http://java.sun.com/products/javabeans/glasgow/jaf.html 

 

转载于:https://www.cnblogs.com/SunWentao/archive/2008/07/30/1256168.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值