Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VB Script to 'type' a file and send via email

Status
Not open for further replies.

jpotucek

Technical User
Jan 26, 2005
144
US
Let me preface by saying that I am not a VB Programmer.
a VB guy that used to work here setup a VB Script to run via windows job scheduler (his code below) to show the file attributes for 2 different files and then email the results.

What I would like to accomplish is to 'type' or display the contents of a small text file and then email the results. Can this be accomplished easily by modifying his script??? if so, can someone help me with the code?
___________________________________
'Script to get the last modified date for a file.

Dim fso, f1, f2

'Set the file attrribute to append
Const ForWriting = 8
Set fso = CreateObject("Scripting.FileSystemObject")


' Get a File object to query.

Set f1 = fso.GetFile("\\server\IT\file1.dmp")

set f2 = fso.GetFile("\\server\IT\file2.db")



Set objEmail = CreateObject("CDO.Message")
objEmail.From = "email_address@server_name.ourdomain.com"
objEmail.To = "Distribution_Group@ourdomain.com"
objEmail.Subject = "IT Operations Status Report-DB backup Status"
objEmail.Textbody = f1.name & " " & f1.DateLastModified & " " & vbcrlf & vbcrlf & _
f2.name & " " & f2.DateLastModified


'== remote smtp configuration


objEmail.Configuration.Fields.Item _
(" = 2

'Name or IP of Remote SMTP Server
objEmail.Configuration.Fields.Item _
(" = "000.000.0.0"

'Server port (typically 25)
objEmail.Configuration.Fields.Item _
(" = 25


objEmail.Configuration.Fields.Update

'==End remote SMTP server configuration section==


objEmail.Send
 
objEmail.Textbody = f1.name & " " & f1.DateLastModified & " " & vbcrlf & vbcrlf & myStr _
& vbCrLf & f2.name & " " & f2.DateLastModified & " " & vbcrlf & vbcrlf & f2.Size

I had caught the typo :) and I'm still getting the
object required: " error on Line 30 (above)

I can't figure out what it means - Object required: "
 
it means that you are trying to access a property or method of something which isnt an object.

so

myStr = "hello"
Msgbox myStr.Text

would produce an error as myStr isnt an object and doesnt support the .Text property

so, in your objEmail.Textbody line we are looking at

objMail, f1 or f2

and the .Properites you are asking to return.
so, try the Msgbox's i said and see which object(or not as the case maybe) and/or which property is causing the problem

i would say it isnt the objMail.Textbody as you prob would have got an error message about this object earlier as you are accessing other properties...but

you could try objMail.Textbody = "hello" b4 you do all your other stuff just to confirm that command is ok
 
Hello jpotucek!

If you wanted to post your full code here, it'd be easier to see why you're getting this error. I'm guessing that in your code, you've changed from using the ".getfile(path)" method to the ".OpenAsTextStream" method. Opening a file as a text stream will not give you access to the same properties that are available using ".getfile".

Good luck!

He who has knowledge spares his words, and a man of understanding is of a calm spirit. Even a fool is counted wise when he holds his peace; when he shuts his lips, he is considered perceptive. - King Solomon
 
It's definitely not objMail.Textbody because I took out everything except objMail.Textbody = "hello" and it works fine. When I start adding back in parameters, it starts failing on objMail.Textbody again (line 31 char 1)

I'll have to play around with it some more.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top