SMTPDEM.~PAS
上传用户:wgxtgt
上传日期:2013-04-09
资源大小:14k
文件大小:6k
- unit smtpdem;
- interface
- uses
- Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
- ComCtrls, StdCtrls, Psock, NMsmtp, ExtCtrls;
- type
- TForm1 = class(TForm)
- PageControl1: TPageControl;
- TabSheet1: TTabSheet;
- TabSheet2: TTabSheet;
- TabSheet3: TTabSheet;
- Edit1: TEdit;
- NMSMTP1: TNMSMTP;
- Label1: TLabel;
- Edit2: TEdit;
- Label2: TLabel;
- Button1: TButton;
- Button2: TButton;
- TabSheet4: TTabSheet;
- StatusBar1: TStatusBar;
- Edit10: TEdit;
- Label11: TLabel;
- Button6: TButton;
- Edit3: TEdit;
- Label3: TLabel;
- Memo1: TMemo;
- Panel1: TPanel;
- GroupBox1: TGroupBox;
- Edit4: TEdit;
- Edit5: TEdit;
- Label4: TLabel;
- Label5: TLabel;
- Edit6: TEdit;
- Label6: TLabel;
- Edit7: TEdit;
- Label7: TLabel;
- Edit8: TEdit;
- Label8: TLabel;
- ListBox1: TListBox;
- Label9: TLabel;
- Button3: TButton;
- Button4: TButton;
- Memo2: TMemo;
- Panel2: TPanel;
- Button5: TButton;
- Label10: TLabel;
- Panel3: TPanel;
- Label13: TLabel;
- Button7: TButton;
- Label12: TLabel;
- OpenDialog1: TOpenDialog;
- Edit9: TEdit;
- Edit11: TEdit;
- procedure Button1Click(Sender: TObject);
- procedure Button6Click(Sender: TObject);
- procedure Button2Click(Sender: TObject);
- procedure NMSMTP1Connect(Sender: TObject);
- procedure NMSMTP1Disconnect(Sender: TObject);
- procedure NMSMTP1Status(Sender: TComponent; Status: String);
- procedure Button3Click(Sender: TObject);
- procedure Button4Click(Sender: TObject);
- procedure Button5Click(Sender: TObject);
- procedure NMSMTP1EncodeStart(Filename: String);
- procedure NMSMTP1EncodeEnd(Filename: String);
- procedure Button7Click(Sender: TObject);
- procedure NMSMTP1MailListReturn(MailAddress: String);
- procedure NMSMTP1ConnectionFailed(Sender: TObject);
- procedure NMSMTP1ConnectionRequired(var handled: Boolean);
- procedure NMSMTP1Failure(Sender: TObject);
- procedure NMSMTP1HostResolved(Sender: TComponent);
- procedure NMSMTP1InvalidHost(var handled: Boolean);
- procedure NMSMTP1PacketSent(Sender: TObject);
- procedure NMSMTP1RecipientNotFound(Recipient: String);
- procedure NMSMTP1SendStart(Sender: TObject);
- procedure NMSMTP1Success(Sender: TObject);
- procedure NMSMTP1HeaderIncomplete(var handled: Boolean;
- hiType: Integer);
- procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
- private
- { Private declarations }
- public
- { Public declarations }
- end;
- var
- Form1: TForm1;
- implementation
- {$R *.DFM}
- procedure TForm1.Button1Click(Sender: TObject);
- begin
- NMSMTP1.Host := Edit1.Text;
- NMSMTP1.Port := StrToInt(Edit2.Text);
- NMSMTP1.UserID := Edit4.Text;
- NMSMTP1.Connect;
- end;
- procedure TForm1.Button6Click(Sender: TObject);
- var
- TmpStr: String;
- begin
- TmpStr := Edit3.Text; // 为了不让用户修改编辑框的内容
- If NMSMTP1.Verify(TmpStr) then
- ShowMessage(TmpStr+'已经验证。')
- else
- ShowMessage(TmpStr+'没有被验证。');
- end;
- procedure TForm1.Button2Click(Sender: TObject);
- begin
- NMSMTP1.Disconnect;
- end;
- procedure TForm1.NMSMTP1Connect(Sender: TObject);
- begin
- StatusBar1.SimpleText := '已经连接。';
- end;
- procedure TForm1.NMSMTP1Disconnect(Sender: TObject);
- begin
- If StatusBar1 <> nil then
- StatusBar1.SimpleText := '断开连接。';
- end;
- procedure TForm1.NMSMTP1Status(Sender: TComponent; Status: String);
- begin
- If StatusBar1 <> nil then
- StatusBar1.SimpleText := status;
- end;
- procedure TForm1.Button3Click(Sender: TObject);
- begin
- If OpenDialog1.Execute then
- ListBox1.Items.Add(OpenDialog1.FileName);
- end;
- procedure TForm1.Button4Click(Sender: TObject);
- begin
- ListBox1.Items.Delete(ListBox1.ItemIndex);
- end;
- procedure TForm1.Button5Click(Sender: TObject);
- begin
- NMSMTP1.PostMessage.FromAddress := Edit6.Text;
- NMSMTP1.PostMessage.FromName := Edit5.Text;
- NMSMTP1.PostMessage.Subject := Edit10.Text;
- NMSMTP1.PostMessage.ToAddress.Add(Edit7.Text);
- NMSMTP1.PostMessage.ToBlindCarbonCopy.Add(Edit9.Text);
- NMSMTP1.PostMessage.ToCarbonCopy.Add(Edit8.Text);
- NMSMTP1.PostMessage.Attachments.AddStrings(Listbox1.Items);
- NMSMTP1.PostMessage.Body.Assign(Memo1.Lines);
- NMSMTP1.SendMail;
- end;
- procedure TForm1.NMSMTP1EncodeStart(Filename: String);
- begin
- StatusBar1.SimpleText := '编码'+Filename;
- end;
- procedure TForm1.NMSMTP1EncodeEnd(Filename: String);
- begin
- StatusBar1.SimpleText := '结束编码'+Filename;
- end;
- procedure TForm1.Button7Click(Sender: TObject);
- begin
- NMSMTP1.ExpandList(Edit11.Text);
- end;
- procedure TForm1.NMSMTP1MailListReturn(MailAddress: String);
- begin
- Memo2.Lines.Add(MailAddress);
- end;
- procedure TForm1.NMSMTP1ConnectionFailed(Sender: TObject);
- begin
- ShowMessage('连接失败。');
- end;
- procedure TForm1.NMSMTP1ConnectionRequired(var handled: Boolean);
- begin
- If MessageDlg('需要连接,进行连接吗?', mtConfirmation, mbOkCancel, 0) = mrOk then
- Begin
- Handled := TRUE;
- NMSMTP1.Connect;
- End;
- end;
- procedure TForm1.NMSMTP1Failure(Sender: TObject);
- begin
- StatusBar1.SimpleText := '失败。';
- end;
- procedure TForm1.NMSMTP1HostResolved(Sender: TComponent);
- begin
- StatusBar1.SimpleText := '解析主机。';
- end;
- procedure TForm1.NMSMTP1InvalidHost(var handled: Boolean);
- var
- TmpStr: String;
- begin
- If InputQuery('无效主机!', '指定一台新的主机:', TmpStr) then
- Begin
- NMSMTP1.Host := TmpStr;
- Handled := TRUE;
- End;
- end;
- procedure TForm1.NMSMTP1PacketSent(Sender: TObject);
- begin
- StatusBar1.SimpleText := IntToStr(NMSMTP1.BytesTotal)+'中的'+IntToStr(NMSMTP1.BytesSent)+'字节数被发送。';
- end;
- procedure TForm1.NMSMTP1RecipientNotFound(Recipient: String);
- begin
- ShowMessage('没有发现容器"'+Recipient+'"');
- end;
- procedure TForm1.NMSMTP1SendStart(Sender: TObject);
- begin
- StatusBar1.simpleText := '正在发送消息';
- end;
- procedure TForm1.NMSMTP1Success(Sender: TObject);
- begin
- StatusBar1.SimpleText := '成功';
- end;
- procedure TForm1.NMSMTP1HeaderIncomplete(var handled: Boolean;
- hiType: Integer);
- begin
- ShowMessage('信息头没有完成.');
- end;
- procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
- begin
- NMSMTP1.Abort;
- end;
- end.