標籤:空間 監控 window
Set objFSO = CreateObject ("Scripting.FileSystemObject")
Set colDrives = objFSO.Drives
Dim msg
For Each objDrive in colDrives
If objDrive.IsReady and objDrive.DriveLetter ="D" and int(objDrive.FreeSpace/(1024*1024*1024))<=400 Then
call CheckFile("備份伺服器10.158.32.142的空間小於40G ,請清理曆史備份檔案或是添加磁碟空間,否則備份將異常終止")
End If
Next
‘定義一個函數,檢查每天的備份是否產生
function CheckFile(byval TextBody )
Const Email_From = "[email protected]" ‘寄件者郵箱
Const Password = "123456" ‘寄件者郵箱密碼
Const Email_To = "[email protected];[email protected]" ‘收件者郵箱
Set CDO = CreateObject("CDO.Message") ‘建立CDO.Message對象
CDO.Subject = "磁碟空間不足" ‘郵件主題
CDO.From = Email_From ‘寄件者地址
CDO.To = Email_To ‘收件者地址
CDO.TextBody = TextBody ‘郵件內文
‘cdo.AddAttachment = "C:\hello.txt" ‘郵件附件檔案路徑
Const schema = "http://schemas.microsoft.com/cdo/configuration/" ‘規定必須是這個,我也不知道為什麼
With CDO.Configuration.Fields ‘用with關鍵字減少代碼輸入
.Item(schema & "sendusing") = 2 ‘使用網路上的SMTP伺服器而不是本地的SMTP伺服器
.Item(schema & "smtpserver") = "smtp.163.com" ‘SMTP伺服器位址
.Item(schema & "smtpauthenticate") = 1 ‘伺服器認證方式
.Item(schema & "sendusername") = Email_From ‘寄件者郵箱
.Item(schema & "sendpassword") = Password ‘寄件者郵箱密碼
.Item(schema & "smtpserverport") = 25 ‘SMTP伺服器連接埠
.Item(schema & "smtpusessl") = True ‘是否使用SSL
.Item(schema & "smtpconnectiontimeout") = 60 ‘串連伺服器的逾時時間
.Update ‘更新設定
End With
CDO.Send ‘發送郵件
End function