mbt masai
 
Welcome !
         

                                
After experiencing a lot of down time, We decided to move this site to CrystalTech.com. CrystalTech.com is powered by only the finest Windows servers providing the best performance, reliability, and value anywhere.

 VBScript to email an alert when a file reaches a size limit

Author Message
bendynet

  • Total Posts : 1
  • Scores: 0
  • Reward points : 0
  • Joined: 8/5/2010
  • Status: offline
VBScript to email an alert when a file reaches a size limit Thursday, August 05, 2010 5:43 PM (permalink)
0
Have you ever wanted to keep track of a file size?  Well, at work, we used to use Outlook 2000, and when the PST file reached 2GB, the file would become corrupt.  So, I built this script to email me whenever the file got past 1.8GB.  With slight modifications, this script could be used to email you when any file reaches a size limit.  I built this script as a logon script for Group Policy, so keep in mind that it's not on a timer or anything of the sort.

 '***********************************
 '
 '    Designed by: Brendon Thrash
 '    Email: bendynet@gmail.com
 '    Website: http://bendynet.com
 '    
 '    This script was designed for a group policy logon
 '    script.  It checks each PST file in the default
 '    Outlook folder location and emails an alert with
 '    the computer name and Windows login name to the
 '    email addresses that you list in the script.
 '
 '***********************************
 
 Dim maxFileSize
 Dim OutputStr
 Dim sendFrom
 Dim sendTo
 Dim sendSMTP
 Dim sendUser
 Dim sendPass
 Dim sendPort
 Dim useSSL
 
 '***********************************
 '    VARIABLES
 '    Change these variables to fit your location
 '
 maxFileSize     =     1843                        'Maximum allowed PST file size in MB
 sendFrom         =    """Outlook PST"" sendemail@gmail.com"    'The FROM name and email that displays on the email (extra quotes are needed)
 sendTo             =    "receiveemail@juno.com"        'The email address to send emails to 
 'sendTo            =    "email1@gmail.com;email2@gmail.com" 'Separate multiple emails with colons like this
 sendSMTP        =    "smtp.gmail.com"            'SMTP server to send emails
 sendUser        =    "username"                    'Username for SMTP server to send emails
 sendPass        =    "password"                    'Password for SMTP server to send emails
 sendPort        =    25                            'Port number for SMTP server to send emails
 useSSL            =    true                        'Does the sending SMTP server use SSL?  true or false
 '
 '***********************************
 
 Set WshShell = Wscript.CreateObject("WScript.Shell")
 Set Envi = WshShell.Environment ("Process")
 Set objFSO = createobject("Scripting.FileSystemObject")
 Set shApp = CreateObject("Shell.application")
 
 'Check to see if the local\app data directory exists
 If objFSO.FolderExists(shApp.Namespace(&H1C&).Self.Path & "\Microsoft\Outlook") Then
     Set FolderPath = objFSO.GetFolder(shApp.Namespace(&H1C&).Self.Path & "\Microsoft\Outlook")
 
 'For each file that ends in "pst", check it's file size
     For Each File in FolderPath.Files
         If objFSO.GetExtensionName(File)="pst" Then
 '1843 is the size of the file in MB
             If cint((File.size / 1024) / 1024) > maxFileSize Then
                 OutputStr = OutputStr & File.name & " : " & cint((File.Size / 1024) / 1024) & "MB" & vbCrLf
             End If
         End If
     Next
 'If there was output, email the information
     If OutputStr <> "" Then
         Set WshNetwork = WScript.CreateObject("WScript.Network")
 
         Const cdoBasic = 1 'basic (clear-text) authentication
 
         Set objMessage = CreateObject("CDO.Message")
         objMessage.Subject = WshNetwork.UserName & "'s pst files on " & WshNetwork.ComputerName & " are too large."
         objMessage.From = sendFrom
         objMessage.To = sendTo
         objMessage.TextBody = OutputStr
 
 'This section provides the configuration information for the remote SMTP server.
         With objMessage.Configuration.Fields
             .Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
             .Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = sendSMTP
 'Type of authentication, NONE, Basic (Base64 encoded), NTLM
             .Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = cdoBasic
         
             .Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = sendUser
             .Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = sendPass
 
             .Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = sendPort
         
             .Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = useSSL
 
             .Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
         
             .Update
         End With
 
         On Error Resume Next
         objMessage.Send
     End If
 Else
     wscript.echo "Error: " & shApp.Namespace(&H1C&).Self.Path & "\Microsoft\Outlook does not exist."
 End If
 


Brendon Thrash
Information Tech, Web Design
http://bendynet.com
#1

    Online Bookmarks Sharing: Share/Bookmark

    Jump to:

    Current active users

    There are 0 members and 1 guests.

    Icon Legend and Permission

    • New Messages
    • No New Messages
    • Hot Topic w/ New Messages
    • Hot Topic w/o New Messages
    • Locked w/ New Messages
    • Locked w/o New Messages
    • Read Message
    • Post New Thread
    • Reply to message
    • Post New Poll
    • Submit Vote
    • Post reward post
    • Delete my own posts
    • Delete my own threads
    • Rate post

    2000-2012 ASPPlayground.NET Forum Version 3.8
    mbt shoes www.wileywilson.com