Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Cannot attach the text file to email
#1
Solved: 11 Years, 4 Months ago
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.
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
Reply
#2
Solved: 11 Years, 4 Months ago
Try this...

Save the text file and close it and then send the mail with attachment
Reply
#3
Solved: 11 Years, 4 Months ago
Thanks ssvali. It worked. Really appreciate your help.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Extracting Email Body from Outlook waseem.khan.91 0 2,163 03-04-2019, 02:53 PM
Last Post: waseem.khan.91
  Extracting Email Body from Outlook waseem.khan.91 0 1,180 03-01-2019, 02:51 PM
Last Post: waseem.khan.91
  Find the email using subject with the help of vb script Raheem Shaik 0 1,681 12-12-2018, 02:57 PM
Last Post: Raheem Shaik
  How to read a text file using FSO from bottom to up order?? vallalarasu.p 0 2,496 10-13-2014, 11:14 AM
Last Post: vallalarasu.p
  how to create text file swayam 1 2,841 05-29-2014, 01:25 PM
Last Post: basanth27

Forum Jump:


Users browsing this thread: 1 Guest(s)