unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, IdComponent, IdTCPConnection, IdTCPClient,
IdMessageClient, IdSMTP, IdBaseComponent, IdMessage;
type
TForm1 = class(TForm)
IdMessage1: TIdMessage;
IdSMTP1: TIdSMTP;
Edit1: TEdit;
Label1: TLabel;
Label4: TLabel;
Edit4: TEdit;
Label5: TLabel;
Edit5: TEdit;
Memo1: TMemo;
Label6: TLabel;
Edit6: TEdit;
Label7: TLabel;
Memo2: TMemo;
Label8: TLabel;
Button1: TButton;
Label2: TLabel;
Edit2: TEdit;
Button2: TButton;
OpenDialog1: TOpenDialog;
procedure Button1Click(Sender: TObject);
procedure IdSMTP1Status(ASender: TObject; const AStatus: TIdStatus;
const AStatusText: String);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
Memo1.Clear;
IdSMTP1.Host:=Edit1.Text;
IdSMTP1.Port:=25;
IdSMTP1.Username:='用户名';
IdSMTP1.Password:='密码';
IdMessage1.From.Address:=Edit4.Text;
IdMessage1.Recipients.EMailAddresses:=Edit5.Text;
IdMessage1.Subject:=Edit6.Text;
IdMessage1.Body.Text:=Memo2.Text;
if FileExists(Edit2.Text) then
TIdAttachment.Create(IdMessage1.MessageParts,Edit2.Text);
try
try
IdSMTP1.Connect;
if IdSMTP1.AuthSchemesSupported.IndexOf('LOGIN')>-1 then
begin
IdSMTP1.AuthenticationType := atLogin;
IdSMTP1.Authenticate;
end;
IdSMTP1.Send(IdMessage1);
except on E:Exception do
Memo1.Lines.Insert(0, 'ERROR: ' + E.Message);
end;
finally
if IdSMTP1.Connected then
IdSMTP1.Disconnect;
end;
end;
procedure TForm1.IdSMTP1Status(ASender: TObject; const AStatus: TIdStatus;
const AStatusText: String);
begin
memo1.Lines.Add('Status:'+AStatusText);
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
OpenDialog1.Execute;
if OpenDialog1.FileName<>'' then
Edit2.Text:=OpenDialog1.FileName;
end;
end.