Unit1.pas
上传用户:yunbing78
上传日期:2018-02-16
资源大小:7k
文件大小:2k
源码类别:

Email服务器

开发平台:

Delphi

  1. unit Unit1;
  2. interface
  3. uses
  4.   Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  5.   Dialogs, StdCtrls, IdMessage, IdBaseComponent, IdComponent,
  6.   IdTCPConnection, IdTCPClient, IdMessageClient, IdSMTP, ExtCtrls;
  7. type
  8.   TForm1 = class(TForm)
  9.     SMTP1: TIdSMTP;
  10.     IdMsg: TIdMessage;
  11.     Button1: TButton;
  12.     Edit1: TEdit;
  13.     Edit2: TEdit;
  14.     Label3: TLabel;
  15.     Memo1: TMemo;
  16.     Edit3: TEdit;
  17.     Button2: TButton;
  18.     Label6: TLabel;
  19.     Edit4: TEdit;
  20.     Label7: TLabel;
  21.     Edit5: TEdit;
  22.     Label8: TLabel;
  23.     Edit6: TEdit;
  24.     OpenDialog1: TOpenDialog;
  25.     Edit7: TEdit;
  26.     Label1: TLabel;
  27.     Label2: TLabel;
  28.     Label4: TLabel;
  29.     Label5: TLabel;
  30.     Bevel1: TBevel;
  31.     Button3: TButton;
  32.     procedure Button1Click(Sender: TObject);
  33.     procedure Button2Click(Sender: TObject);
  34.     procedure Button3Click(Sender: TObject);
  35.   private
  36.     { Private declarations }
  37.   public
  38.     { Public declarations }
  39.   end;
  40. var
  41.   Form1: TForm1;
  42. implementation
  43. {$R *.dfm}
  44. procedure TForm1.Button1Click(Sender: TObject);
  45. begin
  46. SMTP1.AuthenticationType := atLogin;
  47. SMTP1.username:= edit2.text;
  48. SMTP1.Password := edit1.text;
  49. SMTP1.Host := edit3.text;
  50. SMTP1.Port :=25;
  51.   try
  52.    SMTP1.Connect;
  53.    except
  54.     Showmessage('连接SMTP服务器失败!');
  55.     Exit;
  56.     end;
  57.  try
  58.    with IdMsg do
  59.     begin
  60.      body.Clear;
  61.      Body.Assign(memo1.lines);
  62.      From.address := edit5.text;
  63.      Recipients.EMailAddresses :=edit6.text;
  64.      Subject:=edit4.text
  65.    end;
  66.   SMTP1.Send(IdMsg);
  67.   finally
  68.   showmessage('您的信件已成功发送');
  69.   SMTP1.Disconnect;
  70.   end;
  71. end;
  72. procedure TForm1.Button2Click(Sender: TObject);
  73. begin
  74. if opendialog1.Execute then
  75. memo1.Lines.Add(opendialog1.filename);
  76. end;
  77. procedure TForm1.Button3Click(Sender: TObject);
  78. begin
  79.    close;
  80. end;
  81. end.