Mail problems

Can someone please suggest me how we could set up sending emails via nant.I even went through the link, but I was unucessfull.

thank you and welcome Maddy

+1
source share
2 answers

Something like what you will use.

<target name="sendmail"> <mail from=" NAnt@myCompany.com " tolist="${distribution_list}" subject="${mailsubject}" mailhost="${smtpServer}" message="${mailbody}" verbose="true" > <attachments> <include name="${buildroot}/build.log" /> </attachments> </mail> </target> 
+1
source

Here is an example build file. The solution is not very elegant, but it works. All that he does is a file log and before sending it by e-mail, clean it and make a copy to attach it by e-mail.

Note. There are some help links in the code that I used when writing my own build file.

 <description>Sample Build Scripts</description> <property name="nant.onsuccess" value="success" /> <property name="nant.onfailure" value="failure" /> <property name="tolist" value=" youremail@email.com " /> <property name="cclist" value=" youremail@email.com " /> <property name="emailsubject" value="" /> <target name="build" depends="init"> YOUR ACTUAL BUILD CODE GOES HERE </target> <target name="init"> <echo> ----------------------------------------------------------------------------------------------------------------- TASK : INITIALIZE ----------------------------------------------------------------------------------------------------------------- </echo> <loadtasks assembly="nantcontrib-0.85/bin/NAnt.Contrib.Tasks.dll" /> <!-- http://www.basilv.com/psd/blog/2007/how-to-add-logging-to-ant-builds --> <tstamp> <formatter property="timestamp" pattern="yyMMdd_HHmm"/> </tstamp> <property name="build.log.filename" value="build_${timestamp}.log"/> <echo message="build.log.filename: ${build.log.filename}" /> <record name="${build.log.dir}/${build.log.filename}" action="Start" level="Verbose"/> <echo message="Build logged to ${build.log.filename}"/> <echo message="Build Start at: ${datetime::now()}" /> </target> <!--http://www.mail-archive.com/ nant-users@lists.sourceforge.net /msg02485.html--> <target name="success" depends="successresult,sendemail"> <echo>${emailsubject}</echo> </target> <!--http://www.mail-archive.com/ nant-users@lists.sourceforge.net /msg02485.html--> <target name="failure" depends="failureresult,sendemail"> <echo>${emailsubject}</echo> </target> <target name="successresult" > <echo> BUILD FAILED . CHANGE SUBJECT </echo> <property name="emailsubject" value="Web Integration DEV Build : SUCCESS !!!" /> </target> <target name="failureresult" > <echo> BUILD FAILED . CHANGE SUBJECT </echo> <echo message="Task Start at: ${datetime::now()}" /> <property name="emailsubject" value="Web Integration DEV Build : FAILED !!! :)" /> </target> <target name="sendemail" > <echo> ----------------------------------------------------------------------------------------------------------------- SENDING EMAIL ----------------------------------------------------------------------------------------------------------------- </echo> <echo message="Task Start at: ${datetime::now()}" /> <echo>${emailsubject}</echo> <echo>Sending Email</echo> <echo>Attaching File : ${build.log.dir}/email_${build.log.filename}</echo> <echo>Attaching File : ${path.vsshelper.log}/logs/email_${build.log.getlistoffiles}</echo> <!-- Flush is very important before you copy --> <record name="${build.log.dir}/${build.log.filename}" action="Flush" level="Verbose"/> <sleep milliseconds="1000" /> <!-- make a copy --> <copy file= "${build.log.dir}/${build.log.filename}" tofile="${build.log.dir}/email_${build.log.filename}" /> <mail from="${email.from}" tolist="${email.to}" mailhost="${email.host}" message="${emailsubject}" subject="${emailsubject}" > <attachments> <include name="${build.log.dir}/email_${build.log.filename}" /> <include name="${path.vsshelper.log}/logs/email_${build.log.getlistoffiles}" /> </attachments> </mail> </target> 

0
source

Source: https://habr.com/ru/post/1309292/


All Articles