System & Develop/WINDOWS2003. 9. 25. 00:16
'--------------------------------------------------------------------
'
' Mailout using CDONTS.NewMail
'
'--------------------------------------------------------------------

' declare all variables

Dim objSendMail
Dim strTo, strFrom
Dim strSubject, strBody, strEventLog,wbemServices, wbemObjectSet ,strComputer

' mail constants (some are for reference)
Const CdoBodyFormatHTML = 0 ' Body property is HTML
Const CdoBodyFormatText = 1 ' Body property is plain text (default)
Const CdoMailFormatMime = 0 ' NewMail object is in MIME format
Const CdoMailFormatText = 1 ' NewMail object is plain text (default)
Const CdoLow = 0 ' Low importance
Const CdoNormal = 1 ' Normal importance (default)
Const CdoHigh = 2 ' High importance
Const CONVERT_TO_LOCAL_TIME = True

strFrom = "basaaja@basaaja.com" ' change to your email address
strTo = "basaaja@basaaja.com" ' change to the recipient's address
strSubject = "Test Message" ' change to your subject



DateToCheck = now()

dtmStartDate = DateAdd("d", -1,DateToCheck)
dtmEndDate = DateAdd("d", 1,DateToCheck)

strStartYear = DatePart("yyyy",dtmStartDate)
strStartMonth = DatePart("m",dtmStartDate)
strStartDay = DatePart("d",dtmStartDate)

strEndYear = DatePart("yyyy",dtmEndDate)
strEndMonth = DatePart("m",dtmEndDate)
strEndDay = DatePart("d",dtmEndDate)

IF len(strStartMonth) = "1" Then        
        strStartMonth = "0"&strStartMonth
End IF

IF len(strStartDay) = "1" Then        
        strStartDay = "0" & strStartDay
End IF

IF len(strEndMonth) = "1" Then        
        strEndMonth = "0"&strEndMonth
End IF

IF len(strEndDay) = "1" Then        
        strEndDay = "0" & strEndDay
End IF


dtmStartDate = strStartYear & strStartMonth & strStartDay
dtmEndDate = strEndYear & strEndMonth & strEndDay

dtmStartDate = dtmStartDate & "000000.000000+540"
dtmEndDate = dtmEndDate & "000000.000000+540"


strComputer = "INEMPIRE-C0F796"

Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\" & strComputer & "
ootcimv2")
Set colEvents = objWMIService.ExecQuery ("Select * from Win32_NTLogEvent Where TimeWritten >= '" & dtmStartDate & "' and TimeWritten < '" & dtmEndDate & "'")

For each objEvent in colEvents
        strEventLog = strEventLog &  "Category: " & objEvent.Category & vbCrLf
        strEventLog = strEventLog &  "Computer Name: " & objEvent.ComputerName& vbCrLf
        strEventLog = strEventLog &  "Event Code: " & objEvent.EventCode& vbCrLf
        strEventLog = strEventLog &  "Message: " & objEvent.Message& vbCrLf
        strEventLog = strEventLog &  "Record Number: " & objEvent.RecordNumber& vbCrLf
        strEventLog = strEventLog &  "Source Name: " & objEvent.SourceName& vbCrLf
        strEventLog = strEventLog &  "Time Written: " & objEvent.TimeWritten& vbCrLf
        strEventLog = strEventLog &  "Event Type: " & objEvent.Type& vbCrLf
        strEventLog = strEventLog &  "User: " & objEvent.User& vbCrLf
        strEventLog = strEventLog & objEvent.LogFile& vbCrLf
Next


strBody = MakePage(strSubject,strEventLog)

' the following section creates the mail object and sends the mail
Set objSendMail = CreateObject("CDONTS.NewMail")
objSendMail.From = strFrom
objSendMail.To = strTo
objSendMail.Subject = strSubject & " (" & Date() & ")"
objSendMail.Body = strBody

objSendMail.BodyFormat = CdoBodyFormatText
objSendMail.MailFormat = CdoMailFormatMime
objSendMail.Importance = CdoNormal

objSendMail.Send
Set objSendMail = Nothing



' this function returns a properly formatted HTML page
Function MakePage(txtSubject, txtBody)
        Dim txtTemp
        txtTemp = "" & vbCrLf
        txtTemp = txtTemp & "" & vbCrLf
        txtTemp = txtTemp & "" & vbCrLf
        txtTemp = txtTemp & "" & txtSubject & "" & vbCrLf
        txtTemp = txtTemp & txtBody & vbCrLf
        txtTemp = txtTemp & "" & vbCrLf
        txtTemp = txtTemp & ""
        MakePage = txtTemp
End Function

' this function opens a file and returns the file's contents
Function ReadFile(txtFile)
Dim txtTemp, objFS, objFL
Set objFS = CreateObject("Scripting.FileSystemObject")
Set objFL = objFS.OpenTextFile(txtFile)
Do While Not objFL.AtEndOfStream
txtTemp = txtTemp & objFL.ReadLine
txtTemp = txtTemp & vbCrLf
Loop
objFL.Close
Set objFS = Nothing
ReadFile = txtTemp


End Function

'System & Develop > WINDOWS' 카테고리의 다른 글

IIS FTP Passive Mode Port 임의 지정  (0) 2008.10.21
이벤트 ID  (2) 2004.04.22
메일 보내는 VB 스크립트  (0) 2003.09.24
WIN XP 최적화 TIP  (0) 2003.08.18
윈도 2000에서 EMWAC 메일 프로그램 활용  (0) 2002.12.04
Posted by basaaja