nant mail issues

后端 未结 2 1656
灰色年华
灰色年华 2021-01-25 19:13

Can anyone please suggest me how we could configure the sending of mails through nant.I had even gone through the link but i was unsucessfull.

thanks and regards maddy

相关标签:
2条回答
  • 2021-01-25 19:38

    Here is a sample build file. The solution is not very elegant but it works. All it does is logs a file and before sending email flush it and makes a copy of it to attach it in email.

    Note: there are some help links in code which i used while 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 讨论(0)
  • 2021-01-25 19:57

    Something like this is what you would 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>
    
    0 讨论(0)
提交回复
热议问题