07-17-2013, 07:53 PM
Hi Guys,
I'm having trouble trying to attach a file to an email. Following is the script and error message i'm getting when i run it. I close all the processes and restarted the machine and still getting this error.
Error Message:
The process cannot access the file because it is being used by another process.
Any help will be appreciated.
Thanks
Arpan
I'm having trouble trying to attach a file to an email. Following is the script and error message i'm getting when i run it. I close all the processes and restarted the machine and still getting this error.
Code:
Const ForReading = 1, ForWriting = 2
Dim fso, f
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.OpenTextFile("C:\test.txt", 2, True)
f.WriteLine("Testing Script) & vbcrlf
strSMTPFrom = "abc@xyz.com"
strSMTPTo = "abc@xyz.com"
strSMTPRelay = "mail.xyz.com"
strTextBody = "Testing."
'strSubject = "Testing"
strAttachment = "C:\test.txt"
Set oMessage = CreateObject("CDO.Message")
oMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
oMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = strSMTPRelay
oMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
oMessage.Configuration.Fields.Update
oMessage.Subject = strSubject
oMessage.From = strSMTPFrom
oMessage.To = strSMTPTo
oMessage.TextBody = strTextBody
oMessage.AddAttachment strAttachment <--- Getting Error
oMessage.Send
Error Message:
The process cannot access the file because it is being used by another process.
Code:
Line (25): "oMessage.AddAttachment strAttachment".
Any help will be appreciated.
Thanks
Arpan