以下代码是我修改过的样例代码(以便在10.5.8系统下工作),用于使用Indy Mail server中描述的SMTP客户端独立发送电子邮件。
以下来自INDY SMTP服务器示例。
以下来自INDY SMTP服务器示例。
procedure TForm1.btnServerOnClick(Sender: TObject);
begin
IdSMTPServer1.active := true;
end;
procedure TForm1.btnServerOffClick(Sender: TObject);
begin
IdSMTPServer1.active := false;
end;
procedure TForm1.IdSMTPServer1MailFrom(ASender: TIdSMTPServerContext;
const AAddress: string; AParams: TStrings; var VAction: TIdMailFromReply);
begin
// Here we are testing the MAIL FROM line sent to the server.
// MAIL FROM address comes in via AAddress. VAction sets the return action to the server.
// The following actions can be returned to the server:
{ mAccept, mReject }
// For now, we will just always allow the mail from address.
VAction := mAccept;
end;
procedure TForm1.IdSMTPServer1MsgReceive(ASender: TIdSMTPServerContext;
AMsg: TStream; var LAction: TIdDataReply);
var
LMsg : TIdMessage;
LStream : TFileStream;
begin
// When a message is received by the server, this event fires.
// The message data is made available in the AMsg : TStream.
// In this example, we will save it to a temporary file, and the load it using
// IdMessage and parse some header elements.
LStream := TFileStream.Create(ExtractFilePath(Application.exename) + 'test.eml', fmCreate);
Try
LStream.CopyFrom(AMsg, 0);
Finally
FreeAndNil(LStream);
End;
LMsg := TIdMessage.Create;
Try
LMsg.LoadFromFile(ExtractFilePath(Application.exename) + 'test.eml', False);
ToLabel.Caption := LMsg.Recipients.EMailAddresses;
FromLabel.Caption := LMsg.From.Text;
SubjectLabel.Caption := LMsg.Subject;
Memo1.Lines := LMsg.Body;
Finally
FreeAndNil(LMsg);
End;
end;
procedure TForm1.IdSMTPServer1UserLogin(ASender: TIdSMTPServerContext;
const AUsername, APassword: String; var VAuthenticated: Boolean);
begin
// This event is fired if a user attempts to login to the server
// Normally used to grant relay access to specific users etc.
VAuthenticated := True;
end;
procedure TForm1.IdSMTPServer1RcptTo(ASender: TIdSMTPServerContext;
const AAddress: string; AParams: TStrings; var VAction: TIdRCPToReply;
var VForward: string);
begin
VAction := rAddressOk;
end;
procedure TForm1.IdSMTPServer1Received(ASender: TIdSMTPServerContext;
var AReceived: string);
begin
//
end;
我需要将这个项目添加什么才能作为电子邮件发送服务器。
我对原始示例进行了很少的更改(只是为了兼容性),因为我无法理解电子邮件如何发送和接收背后的大部分概念。请告诉我如何使此代码将电子邮件发送到此问题中提供的目标地址(例如:someone@gmail.com)Indy Mail server (smtpclient)。