Paul
Fri Mar 14 16:47:50 CDT 2008
Sorry, I just realized this is not what you're looking for. The script
waits for a file tot pop up in the folder, but you simply want to scan
the folder for a certain extension.
Oh well.... I should read before I post...
Paul Weterings wrote:
> Hi Andrew,
>
> I remembered I once wrote something like that (before I changed my
> phone-system to Asterisk). I think it does just about what you want.
>
> Consider it PD.
>
> Cheers,
>
> Paul
> ---
>
> 'This script monitors a specified Directory (using WMI)
> 'If a file is created in the Directory it picks it up and sends it in an
> E-Mail
> 'SMTP service must be running on the network somewhere.
> 'Author : Paul Weterings
> 'E-Mail : Paul[at]syncpuls.com
> 'Date : Feb 2004
> 'Version : 1.1
>
> Const cdoSendUsingPort = 2
> strComputer = "."
>
> 'You can change the below variables to adapt for your usage.
>
> myEmail = "Paul@syncpuls.com"
> myFrom = "Voicemail@syncpuls.com"
> myMsg = "Open the attachment to listen to the voicemail"
> mySubject = "Voicemail"
> myExtension = "wav"
>
> Dim namestr
> Dim objEmail
> Dim iConf
> Dim Flds
>
> set iConf = CreateObject("CDO.Configuration")
> Set Flds = iConf.Fields
>
> 'Set the CDOSYS configuration fields to use port 25 on the SMTP server.
>
> With Flds
> .Item("
http://schemas.microsoft.com/cdo/configuration/sendusing") =
> cdoSendUsingPort
> .Item("
http://schemas.microsoft.com/cdo/configuration/smtpserver") =
> "mailserver.yoursite.com"
>
> .Item("
http://schemas.microsoft.com/cdo/configuration/SMTPServerPort") = 25
>
> .Item("
http://schemas.microsoft.com/cdo/configuration/SMTPAuthenticate")
> = cdoAnonymous ' 0
>
> .Item("
http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout")
> = 10
> .Update
> End With
>
> 'Set up WMI for checking the Directory
> Set objWMIService = GetObject("winmgmts:" &
> "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
> Set colMonitoredEvents = objWMIService.ExecNotificationQuery ("SELECT *
> FROM __InstanceCreationEvent WITHIN 10 WHERE " & "Targetinstance ISA
> 'CIM_DirectoryContainsFile' and " & "TargetInstance.GroupComponent= " &
> "'Win32_Directory.Name=""c:\\\\temp""'")
>
> 'Infinite loop
> Do
> 'Monitor the directory
> Set objLatestEvent = colMonitoredEvents.NextEvent
>
> 'We only want the folder and filename
> namestr = Split(objLatestEvent.TargetInstance.PartComponent, "=",
> -1, 1)
>
> 'clean the string up, remove extra quotes and slashes
> namestr(1) = Replace(Replace (namestr(1),"\\","\"),"""","")
>
> 'Only take action if we have a .wav file
> If StrComp(myExtension, Right(namestr(1),3), 1) = 0 Then
>
> 'For debugging purposes.
> 'Wscript.Echo namestr(1)
>
> Set objEmail = CreateObject("CDO.Message")
>
> objEmail.Configuration = iConf
> objEmail.From = myFrom
> objEmail.To = myEmail
> objEmail.Subject = mySubject
> objEmail.Textbody = myMsg
> objEmail.AddAttachment(namestr(1))
> objEmail.Send
>
> Set objEmail = Nothing
> End If
> Loop
>
> Set iConf = Nothing
> Set Flds = Nothing
>
>
>
>
> andrew.beeler@gmail.com wrote:
>> I'm trying to figure out how to write a VBScript that will read a
>> folder, and send an email if there is a file with an extension of
>> BAD.
>>
>> I have a block of code that works to send the email using Outlook from
>> other scripts I have in place. I have no idea where to start with the
>> rest of the script. The files will have numerous names, but they will
>> only have an extension of BAD or ERR. If they are there, I want to
>> move them after the email is sent so I don;t continue to get false
>> alerts.
>>
>> Any help pointing me in the right direction would be great!