ActiveX script to email you files from the server


'**********************************************************************
'  Visual Basic ActiveX Script
'**********************************************************************

' Bulit by Steve Ling 6/12/2004
' Change all the setting between the ===== lines

Function main()

Dim strLogFile
Dim strServer
Dim strEmailAddress
Dim strFolder
Dim strName

'==========================================================
'email address goes here.
strEmailAddress = "stevel@domain.com"
'==========================================================

'==========================================================
' Folder where the files are goes here.
strFolder = "K:\Temp"
'==========================================================

'==========================================================
' File Name to look for in Folder this will looks for 
' the name below and anything after it
strName = "Filename"
'==========================================================

'==========================================================
' Domain Name for Email Server
strServer = "domain.com"
'==========================================================

' Get the folder
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder(strFolder)
Set colfiles = objFolder.Files

'Look for log file created today. Note the formatted date.
For Each objFile In colfiles
    If FormatDateTime(objFile.DateCreated, vbShortDate) = FormatDateTime(Now, vbShortDate) Then
	For Each objFileName In colfiles
	If mid(objFileName.Name,1,Len(strName)) = strName Then
        	strLogFile = objFile
	End IF
	Next
    End If
Next

'If log file found attach amd send email using CDO.Message object
If strLogFile > "0" Then
    Set objEmail = CreateObject("CDO.Message")
'==========================================================
    objEmail.From = "validename@" & strServer
'==========================================================
    objEmail.To = strEmailAddress
    objEmail.Subject = "ReCost Estimates: " & strServer
    objEmail.TextBody = "Here are the files! " & Now()

objEmail.Configuration.Fields.Item _
    ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2

'=====================================================================
'You will have to change the Server below to the site email server 
objEmail.Configuration.Fields.Item _
    ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = _
        "mailserver.domain.com"
'=====================================================================

objEmail.Configuration.Fields.Item _
    ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
objEmail.Configuration.Fields.Update

    objEmail.AddAttachment strLogFile
    objEmail.Send

Set objEmail = Nothing

Else

Set objEmail = Nothing

End If

main = DTSTaskExecResult_Success

End Function