0

I am trying to attach a log file to email.

My code is:

**<loadtasks assembly=".../tasks.dll" />
<record name="c:foo\log.txt" action="Start" />
<target name="email">
<mail
      from="abc@foo.com"
      tolist="xyz@foo.com"
      subject="Build"
      message="Build Failed"
      mailhost="smtp.anywhere.net">
      <files>
        <include name="c:foo\log.txt" />
      </files>
      <attachment>
        <include name="c:foo\log.txt" />
      </attachment>
    </mail>
</target>
<record name="c:foo\log.txt" action="Close" />**

My command is:

nant -f:filename.build email -l:c:foo\log.txt

I get following error:

System.Security.SecurityException: Request for the permission of type 'System.Se
curity.Permissions.FileIOPermission, mscorlib, Version=4.0.0.0, Culture=neutral,
 PublicKeyToken=b77a5c561934e089' failed.
   at System.Security.CodeAccessSecurityEngine.Check(Object demand, StackCrawlMa
rk& stackMark, Boolean isPermSet)
   at System.Security.CodeAccessPermission.Demand()
   at System.IO.FileSystemInfo.get_FullName()
   at NAnt.Contrib.Tasks.RecordTask.ExecuteTask()
   at NAnt.Core.Task.Execute()
   at NAnt.Core.Project.InitializeProjectDocument(XmlDocument doc)
   at NAnt.Core.Project.Execute()
   at NAnt.Core.Project.Run()

When i dont use <record> tasks it gives another error like, could not attach txt file. bcoz it being used by another process.

Why am I getting this error?

Rizwana Khan
  • 101
  • 1
  • 1
  • 9
  • I assume the `** – Mightymuke Mar 21 '13 at 03:50
  • Right. its a typo in the question. – Rizwana Khan Mar 21 '13 at 16:31
  • I imagine you're seeing the same issue with ``, I think that's the wrong way to go. Instead of record, could you instead try [copying](http://nant.sourceforge.net/release/0.85-rc2/help/tasks/copy.html) the file then attaching the copy, or determine why `c:\foo\log.txt` is still in use and stopping the process that has it open? – Mightymuke Mar 23 '13 at 07:52

2 Answers2

0

i do something like flush in record task , just before sending email then copy the file to attach in email , hope this workaround works

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

    <record name="${build.log.dir}/${build.log.filename}"       action="Flush" level="Verbose"/>
    <sleep milliseconds="5000" />
    <copy file= "${build.log.dir}/${build.log.filename}" tofile="${build.log.dir}/email_${build.log.filename}" />   
    <copy file= "${path.vsshelper.log}/logs/${build.log.getlistoffiles}" tofile="${path.vsshelper.log}/logs/email_${build.log.getlistoffiles}" />           
aked
  • 5,625
  • 2
  • 28
  • 33
  • i still get error regarding task. i m loading nantconritb tasl.dll. i think there's something, i am missing. But i got it working, using msbuild. i used msbuild command "/flp:" EX:/flp:erroronly;logfile=msbuild.err,i copy it to text file and able to attach to email. without any error. thanks all for your help – Rizwana Khan Apr 09 '13 at 18:00
  • good , that MSbuild worked for you. i think i did flush , copy and then send email – aked Apr 09 '13 at 18:35
0

Make sure that the file is closed before you try to email it.