没有邮件问题

时间:2009-07-01 05:23:35

标签: email nant

任何人都可以建议我如何配置通过nant发送邮件。我甚至已经通过链接,但我没有成功。

感谢和问候 麦迪

2 个答案:

答案 0 :(得分:1)

你会使用这样的东西。

<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 :(得分:0)

这是一个示例构建文件。解决方案不是很优雅,但它的工作原理。它所做的只是记录一个文件,然后在发送电子邮件之前将其冲洗并复制它以将其附加到电子邮件中。

注意:我在编写自己的构建文件时使用的代码中有一些帮助链接。

<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>