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; constly; procedure button2click (sender: TOBJECT); private {private declarations}
Var Form1: TFORM1;
IMPLEMentation
{$ R * .dfm}
Procedure TForm1.Button1Click (Sender: TOBJECT); begin memo1.clear; idsmtp1.host:/EDit1.text; idsmtp1.port: = 25; IDSMTP1.USERNAME: = 'user name'; idsmtp1.password: = '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; end; end;
Procedure TForm1.idsmtp1status (ASENDER: TOBJECT; Const ASTATUS: TIDSTATUS; Const Astatustext: String); begin memo1.lines.add ('status:' astatustext);
Procedure TForm1.Button2Click (Sender: Tobject); Begin OpenDialog1.execute; if OpenDialog1.FileName <> 'Ten Edit2.text: = OPENDIALOG1.FILENAME; END;
End.