首先你的程序应该和系统的某个程序绑定,比如说Explore,这样才能实时监控 其次,你加个触发时间就行了 最后做你自动发送E-mail程序举个简单的例子 监视IE窗口的打开,当IE窗口打开时,自动计时 var iewindow:THandle; begin iewindow:=FindWindow('ieframe',nil); if iewindow<>nil then begin //add yourcode here Timer1.Enabled:=true; //如果你想发邮件可以试试下面的语句 shellexecute(handle,nil,pchar('mailto:[email protected]'),nil,nil,sw_hide); end; end;
在我们机房中我也做过这样的软件,比如UPS报警我会监控UPS的日志文件,发现报警就发mail给管理员,还可以通过手机短信发通知让管理员去检查邮件,这样晚上回家也没关系了。 以下是相关代码: 管理员的地址我放到了配置文件中,这样可以方便更改 我们公司有自己的邮件服务器,我就用它来发送邮件,这样要可靠得多 所以发邮件的错误校验什么我基本上没做 你看一下吧,可能整理的不全,idmessage1和idsmtp1是indy的控件 idmessage1.From.Text:='daemon<[email protected]>'; idmessage1.ReceiptRecipient.Text:='daemon<[email protected]>'; idmessage1.Recipients.EMailAddresses:=tf.ReadString('set','通知地址',''); idmessage1.Subject:=datetimetostr(now())+' UPS报告'; idmessage1.body.clear; reset(tlog);//打开文件把内容读到idmessage1中 while not eof(tlog) do begin readln(tlog,sa); idmessage1.Body.Add(sa); end; closefile(tlog); ok:=false; while not ok do begin try idsmtp1.disConnect; idsmtp1.Connect; idsmtp1.send(idmessage1); idsmtp1.disconnect; finally ok:=true; end; end;
edit.text------mail address
首先你的程序应该和系统的某个程序绑定,比如说Explore,这样才能实时监控
其次,你加个触发时间就行了
最后做你自动发送E-mail程序举个简单的例子
监视IE窗口的打开,当IE窗口打开时,自动计时
var
iewindow:THandle;
begin
iewindow:=FindWindow('ieframe',nil);
if iewindow<>nil then
begin
//add yourcode here
Timer1.Enabled:=true;
//如果你想发邮件可以试试下面的语句
shellexecute(handle,nil,pchar('mailto:[email protected]'),nil,nil,sw_hide);
end;
end;
以下是相关代码:
管理员的地址我放到了配置文件中,这样可以方便更改
我们公司有自己的邮件服务器,我就用它来发送邮件,这样要可靠得多
所以发邮件的错误校验什么我基本上没做
你看一下吧,可能整理的不全,idmessage1和idsmtp1是indy的控件
idmessage1.From.Text:='daemon<[email protected]>';
idmessage1.ReceiptRecipient.Text:='daemon<[email protected]>';
idmessage1.Recipients.EMailAddresses:=tf.ReadString('set','通知地址','');
idmessage1.Subject:=datetimetostr(now())+' UPS报告';
idmessage1.body.clear;
reset(tlog);//打开文件把内容读到idmessage1中
while not eof(tlog) do
begin
readln(tlog,sa);
idmessage1.Body.Add(sa);
end;
closefile(tlog);
ok:=false;
while not ok do
begin
try
idsmtp1.disConnect;
idsmtp1.Connect;
idsmtp1.send(idmessage1);
idsmtp1.disconnect;
finally
ok:=true;
end;
end;
NMSMTp1.UserID := 'xxxx';
NMSMTp1.PostMessage.FromAddress := '[email protected]';
NMSMTp1.PostMessage.FromName := 'xxxx';
NMSMTp1.PostMessage.ToAddress.Text := '[email protected]';
NMSMTp1.PostMessage.Body.Text := 'Body';
NMSMTp1.PostMessage.Subject := 'Subject';
NMSMTp1.Connect;
NMSMTp1.SendMail;
这样写代码,老是提示我没有权限发送邮件。我一下子又找不到这个密码的属性,请大家帮忙。