1,593
社区成员
发帖
与我相关
我的任务
分享
新建一Project1,在form1中添加控件statusbar1(Win32页)和控件IdIPWatch1(Indy Misc页)。接着设置好控件属性:在statusbar1的panels中添加0-TStatusPanel和1-TStatusPanel两项;IdIPWatch1的HistoryEnabled的属性设为False。
编写代码:在TForm1.FormCreate(Sender: TObject)中加入以下代码:
statusbar1.Panels[1].Text:=IdIPWatch1.LocalIP;
OK!按下F9功能键,运行程序,看一下窗口下边状态栏中是不是已经显示了本机的IP地址了?
提示:若IdIPWatch1的HistoryEnabled的属性设为True,则会在程序退出时,自动生成一个文件(文件名为HistoryFileName属性设定的值),记录当前的IP地址。
//********************************************
//声明 : 请转载的朋友不要删除这段声明,谢谢合作!
//作者 : 雨中太阳
//网站 : http://www.SearchAll.cn
//邮箱 : sjt61991@163.com
//Q Q : 48572512
//********************************************
一、用Delphi7上控件 TidMessage,TidSMTP来发送电子邮件(编写:雨中太阳):
定义变量
UserEmail:string;//收件人邮件地址
SmtpAuthType:integer;//验证
SmtpServerUser:string;//登陆SMTP服务器的用户名
SmtpServerPassword:string;//登陆SMTP服务器用到的密码
SmtpServerName:string;//SMTP服务器名.例如:smtp.sohu.com
SmtpServerPort:integer;//SMTP服务器端口,默认的是25
以下是发送过程.其中idMsgSend:TidMessage,SMTP:TidSMTP;分别在Indy Clients和Indy Misc页上.
procedure TForm1.BitBtn1Click(Sender: TObject);
begin
with IdMsgSend do
begin
Body.Assign(Memo1.Lines);
From.Text := 'sjt61991@sohu.com'; //发件人
ReplyTo.EMailAddresses :=UserEmail ;
Recipients.EMailAddresses :=UserEmail; { To: header }//收件人地址
Subject := 'kkkkkkkkkkk'; { Subject: header } //邮件主体
// Priority := TIdMessagePriority(cboPriority.ItemIndex); { Message Priority } //邮件优先级
// CCList.EMailAddresses := edtCC.Text; {CC} //抄送
// BccList.EMailAddresses := edtBCC.Text; {BBC} //暗送
if chkReturnReciept.Checked then //需要已读回执
begin {We set the recipient to the From E-Mail address }
ReceiptRecipient.Text := From.Text;
end
else
begin {indicate that there is no receipt recipiant}
ReceiptRecipient.Text := '';
end;
end;
authentication settings //是否需要验证
case SmtpAuthType of
0: SMTP.AuthenticationType := atNone;
1: SMTP.AuthenticationType := atLogin; {Simple Login }
end;
SMTP.Username := SmtpServerUser;
SMTP.Password := SmtpServerPassword;
{General setup}
SMTP.Host := SmtpServerName;
SMTP.Port := SmtpServerPort;
{now we send the message}
SMTP.Connect;
try
SMTP.Send(IdMsgSend);
showmessage('发送成功!');
finally
SMTP.Disconnect;
showmessage('发送失败!');
end;
end;
//二、判断是否是邮件地址
function IsEMail(EMail: String): Boolean;
var
s: String;
ETpos: Integer;
begin
ETpos:= pos('@',EMail);
if ETpos > 1 then
begin
s:= copy(EMail,ETpos+1,Length(EMail));
if (pos('.',s) > 1) and (pos('.',s) < length(s)) then
Result:= true
else Result:= false;
end
else
Result:= false;
end;
//三、根据输入的邮件地址从POP,SMTP地址中取得POP3,和 SMTP的地址.如果返回空,则是没有找到,可能是没有收录.
//地址的格式为.从FoxMail5.0得来的.
{/////////////////////////////////////////////////////////
foxmail.com.cn<p>pop.foxmail.com.cn<s>smtp.foxmail.com.cn
mail.bodachina.com<p>mail.bodachina.com<s>mail.bodachina.com
21cn.com<p>pop.21cn.com<s>smtp.21cn.com
}////////////////////////////////////////////////////////////
function GetPOPandSMTPFromTxt(FileName, EmailStr: string): string;
var
i,lenStr:integer;
AtEmail,TempStr,POPStr,SMTPStr:string;
myFile:TextFile;
begin
Result:='';
lenStr:=Pos('@',EmailStr);
AtEmail:=Copy(EmailStr,lenStr+1,Length(EmailStr)-lenStr);
AssignFile(myFile,FileName);
Reset(myFile);
While not Eof(myFile) do
begin
Readln(myFile,TempStr);
if AtEmail=Copy(TempStr,1,Pos('<p>',TempStr)-1) then
begin
POPStr:=Copy(TempStr,Pos('<p>',TempStr)+3,Pos('<s>',TempStr)-Pos('<p>',TempStr)-3);
SMTPStr:=Copy(TempStr,Pos('<s>',TempStr)+3,length(TempStr)-Pos('<s>',TempStr)-2);
Result:=POPStr+'|'+SMTPStr;
end;
end;
CloseFile(myFile);
end;
//用法如下:
procedure TForm1.Button2Click(Sender: TObject);
var
POPStr,SMTPStr,myResult:string;
begin
myResult:=GetPOPandSMTPFromTxt('E:\我的程序\popnsmtp.TXT',Edit1.Text);
if myResult<>''then
begin
POPStr:=Copy(myResult,1,Pos('|',myResult)-1);
SMTPStr:=Copy(myResult,Pos('|',myResult)+1,length(myResult));
showmessage(POPSTr);
showmessage(SMTPStr);
end;
end;
这是一封测式邮件,this is test eamil0x1114ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff