DocInput holds all the information about the current transfer, including the headers, the
number of bytes transferred, and the message data itself. Although not shown in this example,
you may call DocInput's SetData method if DocInput.State = icDocData to encode the data before
each block is sent.}
procedure TMail.SMTP1DocInput(Sender: TObject;
const DocInput: DocInput);
begin
case DocInput.State of
icDocBegin:
SMTPStatus.SimpleText := 'Initiating document transfer';
icDocHeaders:
SMTPStatus.SimpleText := 'Sending headers';
icDocData:
if DocInput.BytesTotal > 0 then
SMTPStatus.SimpleText := Format('Sending data: %d of %d bytes (%d%%)',
[Trunc(DocInput.BytesTransferred), Trunc(DocInput.BytesTotal),
Trunc(DocInput.BytesTransferred/DocInput.BytesTotal*100)])
else
SMTPStatus.SimpleText := 'Sending...';
icDocEnd:
if SMTPError then
SMTPStatus.SimpleText := 'Transfer aborted'
SMTPStatus.SimpleText := Format('Mail sent to %s (%d bytes data)', [eTo.Text,
Trunc(DocInput.BytesTransferred)]);
end;
SMTPStatus.Update;
{The Error event is called whenever an error occurs in the background processing. In
addition to providing an error code and brief description, you can also access the SMTP
component's Errors property (of type icErrors, an OLE object) to get more detailed
information}
procedure TMail.SMTP1Error(Sender: TObject; Number: Smallint;
var Description: WideString; Scode: Integer; const Source,
HelpFile: WideString; HelpContext: Integer; var CancelDisplay: WordBool);
var
I: Integer;
ErrorStr: string;
SMTPError := True;
CancelDisplay := True;
{Get extended error information}
for I := 1 to SMTP1.Errors.Count do
ErrorStr := Format(#13'(%s)', [SMTP1.Errors.Item(I).Description]);
{Display error code, short and long error description}
MessageDlg(Format('%d - %s%s', [Number, Description, Trim(ErrorStr)]), mtError, [mbOK], 0);
{Unlike POP, SMTP does not require a user account on the host machine, so no user
authorization is necessary}
procedure TMail.SMTPConnectBtnClick(Sender: TObject);
if SMTP1.State = prcConnected then
SMTP1.Quit
if SMTP1.State = prcDisconnected then
SMTP1.RemoteHost := eSMTPServer.Text;
SMTPError := False;
SMTP1.Connect(NoParam, NoParam);
{Unlike SMTP, users must be authorized on the POP server. The component defines
a special protocol state, popAuthorization, when it requests authorization. If
authorization is successful, the protocol state changes to popTransaction and
POP commands can be issued. Note that server connection is independent of the
authorization state.}
procedure TMail.POP1ProtocolStateChanged(Sender: TObject;
ProtocolState: Smallint);
case ProtocolState of
popAuthorization:
POP1.Authenticate(POP1.UserID, POP1.Password);
popTransaction:
ConnectStatus.SimpleText := Format('User %s authorized on server %s', [eUsername.Text,
ePOPServer.Text]);
{This event is called every time the connection status of the POP server changes}
procedure TMail.POP1StateChanged(Sender: TObject; State: Smallint);
case State of
prcConnecting:
ConnectStatus.SimpleText := 'Connecting to POP server: '+POP1.RemoteHost+'...';
prcResolvingHost:
ConnectStatus.SimpleText := 'Resolving Host';
prcHostResolved:
ConnectStatus.SimpleText := 'Host Resolved';
prcConnected:
ConnectStatus.SimpleText := 'Connected to POP server: '+POP1.RemoteHost;
POPConnectBtn.Caption := 'Disconnect';
prcDisconnecting:
ConnectStatus.SimpleText := 'Disconnecting from POP server: '+POP1.RemoteHost+'...';
prcDisconnected:
ConnectStatus.SimpleText := 'Disconnected from POP server: '+POP1.RemoteHost;
POPConnectBtn.Caption := 'Connect';
ePOPServer.Enabled := not (State = prcConnected);
eUsername.Enabled := not (State = prcConnected);
ePassword.Enabled := not (State = prcConnected);
addition to providing an error code and brief description, you can also access the POP
procedure TMail.POP1Error(Sender: TObject; Number: Smallint;
POPError := True;
if POP1.ProtocolState = popAuthorization then
ConnectStatus.SimpleText := 'Authorization error';
for I := 1 to POP1.Errors.Count do
ErrorStr := Format(#13'(%s)', [POP1.Errors.Item(I).Description]);
{POP requires a valid user account on the host machine}
procedure TMail.POPConnectBtnClick(Sender: TObject);
if (POP1.State = prcConnected) and (POP1.ProtocolState = popTransaction)
and not POP1.Busy then
mReadMessage.Lines.Clear;
POP1.Quit;
end
if POP1.State = prcDisconnected then
POP1.RemoteHost := ePOPServer.Text;
POP1.UserID := eUserName.Text;
POP1.Password := ePassword.Text;
POP1.Connect(NoParam, NoParam);
{The DocOutput event is the just like the DocInput event in 'reverse'. It is called each time
the component's DocOutput state changes during retrieval of mail from the server. When the
state = icDocData, you can call DocOutput.GetData to decode each data block based on the MIME
content type specified in the headers.}
procedure TMail.POP1DocOutput(Sender: TObject; const DocOutput: DocOutput);
Buffer: WideString;
case DocOutput.State of
POPStatus.SimpleText := 'Initiating document transfer';
POPStatus.SimpleText := 'Retrieving headers';
for I := 1 to DocOutput.Headers.Count do
mReadMessage.Lines.Add(DocOutput.Headers.Item(I).Name+': '+
DocOutput.Headers.Item(I).Value);
POPStatus.SimpleText := Format('Retrieving data - %d bytes',
[Trunc(DocOutput.BytesTransferred)]);
Buffer := DocOutput.DataString;
mReadMessage.Text := mReadMessage.Text + Buffer;
if POPError then
POPStatus.SimpleText := 'Transfer aborted'
POPStatus.SimpleText := Format('Retrieval complete (%d bytes data)',
POPStatus.Update;
{Retrieve message from the server}
procedure TMail.udCurMessageClick(Sender: TObject; Button: TUDBtnType);
if (POP1.State = prcConnected) and (POP1.ProtocolState = popTransaction) then
POPError := False;
POP1.RetrieveMessage(udCurMessage.Position);
{The RefreshMessageCount event is called whenever the RefreshMessageCount method is
called, and also when a connection to the POP server is first made}
procedure TMail.POP1RefreshMessageCount(Sender: TObject;
Number: Integer);
FMessageCount := Number;
udCurMessage.Max := Number;
udCurMessage.Enabled := Number <> 0;
lMessageCount.Caption := IntToStr(Number);
if Number > 0 then
udCurMessage.Min := 1;
udCurMessage.Position := 1;
end.
файл webbrows.dpr
program Webbrows;
uses
Forms,
main in 'Main.pas' {MainForm},
Страницы: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17