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!

Checking a file, deleting and emailing notification ...

Status
Not open for further replies.

MojoZig

Technical User
Sep 27, 2005
61
US
I need a script that will check to see if a text file is on a server at a specific location: if it is, then it needs deleted, else an email notification needs sent. Sounded easy ..

Code:
Set objFSO = CreateObject("Scripting.FileSystemObject")

If objFSO.FileExists("C:\FSO\ScriptLog.txt") Then
    'Set objFolder = objFSO.GetFile("C:\FSO\ScriptLog.txt")
    objFSO.DeleteFile("C:\FSO\ScriptLog.txt")
Else
    'Wscript.Echo "File does not exist."
Set objEmail = CreateObject("CDO.Message")

objEmail.From = "supportemail@address.org"
objEmail.To = "myemail@address.org"
objEmail.Subject = "File DOES NOT EXIST!" 
objEmail.Textbody = "Your file does not exist, you have issues now ..."
objEmail.Send

End If

This scipt does delete the file if it's there, but if it's not there, it gets an error:

I get an error:
Line 15 Char 1 The "SendUsing" configuration value is invalid. Code 80040220 Source CDO.message.1

Is this because I'm doing it from my PC and not a server? How would I get it to mail from our mail server?

Thanks!

TT


 
Do a keyword search in this forum for CreateObject("CDO.Message")
Tip: you need a CDO.Configuration object.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Actually that did help, I noticed folks were using the other script from M$'s script repository so I used it as well:

Code:
Set objFSO = CreateObject("Scripting.FileSystemObject")

If objFSO.FileExists("C:\FSO\ScriptLog.txt") Then
    'Set objFolder = objFSO.GetFile("C:\FSO\ScriptLog.txt")
    objFSO.DeleteFile("C:\FSO\ScriptLog.txt")
Else

Set objEmail = CreateObject("CDO.Message")

objEmail.From = "EMAIL@ADDRESS.COM"
objEmail.To = "EMAIL@ADDRESS.COM"
objEmail.Subject = "Your File Missing ..." 
objEmail.Textbody = "Your file is missing, you have issues now!"
objEmail.Configuration.Fields.Item _
    ("[URL unfurl="true"]http://schemas.microsoft.com/cdo/configuration/sendusing")[/URL] = 2
objEmail.Configuration.Fields.Item _
    ("[URL unfurl="true"]http://schemas.microsoft.com/cdo/configuration/smtpserver")[/URL] = _
        "SERVERIPADDRESS" 
objEmail.Configuration.Fields.Item _
    ("[URL unfurl="true"]http://schemas.microsoft.com/cdo/configuration/smtpserverport")[/URL] = 25
objEmail.Configuration.Fields.Update
objEmail.Send


End If

Just change the ip address of the mail server and your email addresses and it works fine ... I guess we have a system that drops a file but won't overright it if it's there and it's not a permissions thing ... go figure ...

T
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top