NAnt.Core.Ext: MailLogger2 and MailTask2

NAnt 目前的版本虽然支持 Email 的发送,但其不支持SSL的Email,这样我们要想直接使 NAnt 通过GMail 或126 等邮箱发送就不可能了。究其原因,是因为 NAnt.Core.Tasks.MailTask 和 NAnt.Core.MailLogger 中是用 System.Web.Mail.MailMessage 类构造电子邮件的属性和方法,这各类没有提供SSL 的支持。而 System.Web.Mail 这个namespace 下的所有类已经被 System.Net.Mail 所替代。NAnt.Core.Ext就是基于这个对NAnt 的一个扩展。

下载地址:NAnt.Core.Ext.zip

 

  1  <? xml version="1.0" encoding="utf-8"  ?>
  2  < project  name ="MailLogger Test"  default ="build" >
  3     < property  name ="nant.settings.currentframework"  value ="net-4.0"   />
  4     < property  name ="Platform"  value ="Win32"  overwrite ="false"   />
  5     < property  name ="build.configuration"  value ="debug"   />
  6     < property  name ="Dir.Vault"  value ="${directory::get-parent-directory(project::get-base-directory())}"  overwrite ="false"   />
  7     < property  name ="Dir.Framework"  value ="${framework::get-framework-directory(framework::get-target-framework())}"  overwrite ="false"   />
  8 
  9     < property  name ="Dir.Solution"  value ="${Dir.Vault}\TestSolution"  overwrite ="false"   />
 10     < property  name ="Dir.SolutionFile"  value ="${Dir.Solution}\Test.sln"  overwrite ="false" />
 11     < property  name ="nant.onfailure"  value ="failed"   />
 12     < property  name ="nant.onsuccess"  value ="succeeded"   />
 13 
 14     < target  name ="loadExt" >
 15       < loadtasks >
 16         < fileset >
 17           < include  name ="${Dir.Vault}\BuildFiles\bin\NAnt.Core.Ext.dll"   />
 18         </ fileset >
 19       </ loadtasks >
 20     </ target >
 21 
 22     < target  name ="build"  depends ="loadExt" >
 23       < call  target ="clean"  failonerror ="false"   />
 24       < call  target ="syncCode"  failonerror ="false"   />
 25       < call  target ="msBuild"  failonerror ="true"   />
 26     </ target >
 27 
 28     < target  name ="clean" >
 29       < delete  dir ="${Dir.Solution}\Output" />
 30     </ target >
 31 
 32     < target  name ="msBuild"  depends ="" >
 33       < exec  program ="${Dir.Framework}\MSBuild.exe"
 34            commandline ="${Dir.SolutionFile} /t:rebuild /p:Configuration=${build.configuration} /l:FileLogger,Microsoft.Build.Engine;logfile=MsBuild.log append=true;verbosity=diagnostic;encoding=utf-8 /verbosity:quiet"  workingdir ="."   />
 35     </ target >
 36 
 37     < target  name ="syncCode"  depends ="" >
 38       < p4sync
 39         view ="//path/..."
 40        user ="username"
 41        port ="server:port"
 42        client ="clientname"
 43        force ="false"
 44        verbose ="false" />
 45     </ target >
 46 
 47     <!--  Send Email  -->
 48     < property  name ="Mail.Mailhost"  value ="smtp.gmail.com"   />
 49     < property  name ="Mail.From"  value ="****@gmail.com"   />
 50     < property  name ="Mail.To"  value ="****@126.com"   />
 51     < property  name ="Mail.Username"  value ="****"   />
 52     < property  name ="Mail.Password"  value ="****"   />
 53 
 54     <!--  cmd: nant -buildfile:default.build -logger:NAnt.Core.MailLogger -l:NantBuild.log  -->
 55     < property  name ="MailLogger2.mailhost"  value ="${Mail.Mailhost}"   />
 56     < property  name ="MailLogger2.from"  value ="${Mail.From}"   />
 57     < property  name ="MailLogger2.smtp.username"  value ="${Mail.Username}"   />
 58     < property  name ="MailLogger2.smtp.password"  value ="${Mail.Password}"   />
 59     < property  name ="MailLogger2.smtp.enablessl"  value ="true"   />
 60     < property  name ="MailLogger2.body.encoding"  value ="utf-8"   />
 61     < property  name ="MailLogger2.smtp.port"  value ="587"   />    <!-- Port: 465 or 587 -->   
 62     < property  name ="MailLogger2.failure.notify"  value ="true"   />
 63     < property  name ="MailLogger2.success.notify"  value ="true"   />
 64     < property  name ="MailLogger2.failure.to"  value ="${Mail.To}"   />
 65     < property  name ="MailLogger2.success.to"  value ="${Mail.To}"   />
 66     < property  name ="MailLogger2.failure.subject"  value ="Build failure!"   />
 67     < property  name ="MailLogger2.success.subject"  value ="Build successful!"   />
 68 
 69     < target  name ="succeeded" >
 70       < mail2
 71               mailhost ="${Mail.Mailhost}"
 72              isSSL ="true"
 73              username ="${Mail.Username}"
 74              password ="${Mail.Password}"
 75              port ="587"
 76              from ="${Mail.From}"
 77              tolist ="${Mail.To}"
 78              subject ="Build succeeded!"
 79              isbodyhtml ="false"
 80              message ="Build succeeded!" >
 81         < files >
 82           < include  name ="*.log" />
 83         </ files >
 84         < attachments >
 85           < include  name ="*.log" />
 86         </ attachments >
 87       </ mail2 >
 88     </ target >
 89 
 90     < target  name ="failed" >
 91       < mail2
 92               mailhost ="${Mail.Mailhost}"
 93              isSSL ="true"
 94              username ="${Mail.Username}"
 95              password ="${Mail.Password}"
 96              port ="587"
 97              from ="${Mail.From}"
 98              tolist ="${Mail.To}"
 99              subject ="Build failed!"
100              isbodyhtml ="false"
101              message ="Build failed!" >
102         < files >
103           < include  name ="*.log" />
104         </ files >
105         < attachments >
106           < include  name ="*.log" />
107         </ attachments >
108       </ mail2 >
109     </ target >
110    
111  </ project >

 

 

你可能感兴趣的:(NAnt.Core.Ext: MailLogger2 and MailTask2)