Skip to content

Instantly share code, notes, and snippets.

@typomedia
Forked from typomedia/mail.newfiles.vbs
Last active August 29, 2015 14:00
Show Gist options
  • Save typomedia/11408759 to your computer and use it in GitHub Desktop.
Save typomedia/11408759 to your computer and use it in GitHub Desktop.
' Copyright 2013 Typomedia Foundation. All rights reserved.
' Released under GPL version 3.
'
' VBS New Files Mailer v1.1
' Send a mail if files of a specific dir are newer than x minutes
Const intMin = 60 'Minutes
Set oArgs = WScript.Arguments
Set fso = CreateObject("Scripting.FileSystemObject")
Message = GetFiles(oArgs.Item(1))
If Message <> "" then 'if Message is not empty
SendMail(Message)
'MsgBox(Message)
End if
Function SendMail(Message)
Set objEmail = CreateObject("CDO.Message")
objEmail.From = """Windows Server"" <[email protected]>"
objEmail.To = oArgs.Item(0)
'objEmail.CC = "[email protected]"
objEmail.Subject = "New Files"
objEmail.HTMLBody = "<html><body><pre>" & Message & "</pre></body></html>"
objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.provider.tld"
objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusername") = "[email protected]"
objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "<password>"
objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 465
objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True
objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
objEmail.Configuration.Fields.Update
objEmail.Send
End Function
Function GetFiles(strPath)
On Error Resume Next
Set objFolder = fso.GetFolder(strPath)
'Get all Files from folder
For Each objFile In objFolder.Files
fileCreateDate = objFile.DateCreated
'fileModDate = objFile.DateLastModified
'fileAccessDate = objFile.DateLastAccessed
If Err.Number = 0 Then
If DateDiff("n", fileCreateDate, Now) < intMin Then '< newer than
strFiles = strFiles & objFile.Path & vbNewLine
End if
End if
Next
'Get all subfolders
For Each objFolder In objFolder.SubFolders
'Get all Files from subfolder
strFiles = strFiles & GetFiles(objFolder.Path)
Next
GetFiles = strFiles
End Function
@typomedia
Copy link
Author

USAGE: newfiles.vbs [email protected] "\SERVER\Incoming"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment