Sign in to follow this  
Followers 0
Snax

"cannot access file" when sending attachments with _INetSmtpMailCom

3 posts in this topic

#1 ·  Posted (edited)

I am trying to send an email (using the _InetSmtpMailCom function) with a text file attachment which is a log file I am compiling during the running of my script.

My first version of my script used 1 standard log file. It was appended to every time I ran my script. Everything worked fine in terms of emailing the attachment. Then I decided I wanted to have a new log file every time the script ran so I started doing the following:

; Assign date/timestamp

$date_time = @MON&@MDAY&@YEAR & "-" & @HOUR&@MIN&@SEC

; Assign report name/path to variable

$log_file = "N:\AutoIT\logfiles\report_log_"&$date_time&".txt"

; Create 0 byte flat file

$log = FileWrite($log_file, "")

; Open flat file for writing

$report_log = FileOpen($log_file, 1)

At the end of the script I:

FileClose($log_file)

$email_res = _SMTPEmail($log_file)

However, I get an error message stating that the process cannot access the file because it is being used by another process.

Again, this didn't happen when I was just opening the same file every time to append the new log data to.

Any ideas why this may be getting stuck like this?

Apparently, it's my script that is locking the file because I wrote a little test script to do nothing but send that same file and it work fine:

#Include <email_func.au3>

$email_res2 = _SMTPEmail("N:\AutoIT\logfiles\report_log_01172007-114308.txt")

Edited by Snax

Share this post


Link to post
Share on other sites



$log_file = "N:\AutoIT\logfiles\report_log_"&$date_time&".txt"

; Create 0 byte flat file

$log = FileWrite($log_file, "")

; Open flat file for writing

$report_log = FileOpen($log_file, 1)

At the end of the script I:

FileClose($log_file)

You are not closing the filehandle $report_log

this : FileClose($log_file)

should be FileClose($report_log)

:)


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

Egad! :D

Thanks a bunch, that was it! Sometimes it just take a set of new eyes. :)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0