文件监控


DIM  strDate   

DIM  strDatestringOld

DIM  strPath01 , strPath02,strPath03

DIM fs

DIM  Textbody 


strDate = Date

strDatestringOld=Year(strDate) & Right("0" & Month(strDate),2) & Right("0" & Day(strDate),2)&".rar"


strPath="D:\backup\10.65.14.61\"&strDatestringOld

strPath01="D:\backup\10.65.14.61\"&strDatestringOld


set fs =createobject("scripting.filesystemobject")


If fs.fieExists(strPath01)=fales Then

  Textbody = "以下备份文件未生成" & vbcrlf & strPath01

End If


If fs.fieExists(strPath02)=fales Then

  Textbody =Textbody & vbcrlf & strPath02

End If


if Textbody <>"" then

 call  CheckFile(Textbody) 

end if 


'定义一个函数,检查每天的备份是否生成


function CheckFile(byval TextBody )

   Const Email_From = "dwchaoyue@163.com" '发件人邮箱 

Const Password = "123456" '发件人邮箱密码 

Const Email_To = "835223319@qq.com;v.dengwang@snda.com" '收件人邮箱 


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 


代码参考链接:

http://www.jb51.net/article/26105.htm