關於寫SMTP 認證程式的問題 |
缺席
|
cutehsu
一般會員 發表:1 回覆:2 積分:0 註冊:2003-07-02 發送簡訊給我 |
|
cutehsu
一般會員 發表:1 回覆:2 積分:0 註冊:2003-07-02 發送簡訊給我 |
Unit Unit1; interface uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient,
IdSMTP, IdMessageClient, ComCtrls; type
TForm1 = class(TForm)
Label1: TLabel;
Label2: TLabel;
Edit1: TEdit;
Label3: TLabel;
Edit2: TEdit;
Edit3: TEdit;
Button1: TButton;
Button2: TButton;
IdSMTP1: TIdSMTP;
StatusBar1: TStatusBar;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end; var
Form1: TForm1; implementation {$R *.DFM} procedure TForm1.Button1Click(Sender: TObject);
begin
//SMTP server 認證的方式
// IdSMTP1.AuthenticationType := atNone; //不需認證方式
IDSMTP1.AuthenticationType := atLogin; {Simple Login}
IdSMTP1.UserId := Edit1.Text; //認證帳號
IdSMTP1.Password := Edit3.Text; //認證密碼 if Trim(string(Edit3.Text)) = '' then //判斷密碼為空白如果為空白就show 訊息
begin
ShowMessage ('沒有輸入密碼');
exit;
end; IdSMTP1.Host := Edit2.Text; //送信主機
IdSMTP1.Port := 25; //送信主機PORT
IdSMTP1.Connect; //網路連結smtp主機
try
IdSMTP1.Authenticate;
ShowMessage('login OK'); //顯示成功
IdSMTP1.Disconnect;
except
on e : exception do //例外處理的
begin
ShowMessage( 'login error' ); //錯誤訊息顯示
// ShowMessage( e.Message ); //錯誤訊息顯示
IdSMTP1.Disconnect; //關閉網路連結
end;
end;
end; procedure TForm1.Button2Click(Sender: TObject);
begin
Close;
end; end.
|
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |