发信人: leezy (【HIT】穆子), 信区: BorlandDev
标 题: 用delphi实现电子邮件到达通知
发信站: 哈工大紫丁香 (2002年01月19日15:50:32 星期六), 站内信件
摘 要:电子邮件到达通知
关键字:电子邮件到达通知
类 别:网络
首先新建一个form,然后在窗体上放上一个NMPOP31控件和一个Timer1控件.
然后在对象监视器里将NMPOP31的属性设置如下:
host--------->263.net //假如你的信箱在263上,以下为几个常用的pop服务
器:pop.china.com,pop.sohu.com,一般为pop+服务器名
password----->your password //你的密码
port--------->110 //端口
timeout------>40000 //
userid------->your username //你的用户名
reportlever-->2
Timer1的属性设置如下:
interval----->4000
enabled------>false
Tform1的属性设置如下:
windowstate-------->wsMinimized
autosize----------->true
声明全局变量 i:integer;
下面我们来实现上面所说的功能:
procedure TForm1.FormCreate(Sender: TObject);
begin
NMPOP31.Connect; //与服务器建立连接
i:=NMPOP31.MailCount; //得到邮件的初始份数
NMPOP31.Disconnect; //然后断开连接
timer1.Enabled:=true; //Timer1开始工作
SETwindoWlong(Application.Handle,GWL_EXSTYLE,WS_EX_TOOLWINDOW); //程序在后
台工作
procedure TForm1.Timer1Timer(Sender: TObject);
begin
NMPOP31.Connect;
if (NMPOP31.MailCount>i) then
BEGIN
sndplaysound(pchar('C:\ezPeer\bin\almsg.wav'),snd_async or snd_nodefault);
//声音提示,你可以录制你自己的提示声音
i:=NMPOP31.MailCount;
END;
NMPOP31.DisConnect;
end;
end;
以下是NMPOP31的几条异常处理语句:
procedure TForm1.NMPOP31AuthenticationFailed(var Handled: Boolean);
begin
messagebeep(MB_ICONHAND); //声音提示,电脑将发出"都"的一声
showmessage('用户名/密码有误'); //给出错误提示
end;
procedure TForm1.NMPOP31ConnectionFailed(Sender: TObject);
begin
messagebeep(MB_ICONHAND);
showmessage('连接失败');
form1.close;
end;
procedure TForm1.NMPOP31HostResolved(Sender: TComponent);
begin
messagebeep(MB_ICONHAND);
showmessage('无效的主机名');
form1.Close;
end;
最后不要忘了在uses中加上shellapi.ok,现在我们只需按一下F9,你就可以享受自己的劳
动成果了.
--
°★.☆° .★·°∴°★.°·∴°☆ ·°∴° ☆..·°∴°.☆°★°∴°
※ 来源:·哈工大紫丁香 bbs.hit.edu.cn·[FROM: 202.118.230.122]
Powered by KBS BBS 2.0 (http://dev.kcn.cn)
页面执行时间:3.395毫秒