使用 INDY SMTP 服务器
以下代码是我对示例进行修改(与 10.5.8 一起使用)的内容,以便使用 Indy Mail 服务器
以下是来自 INDY smtpserver 示例,
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;
我必须向此项目添加什么才能用作电子邮件发送服务器。
我没有对原始示例进行太多更改(仅出于兼容性目的),因为我无法理解如何发送和接收电子邮件背后的大多数概念。请解释一下如何使此代码将电子邮件发送到目的地(例如: [email protected] ])在这个问题中给出Indy 邮件服务器(smtpclient),
following code is what i modified(to work with 10.5.8) form the sample in order to send email independently using the smtp client described in Indy Mail server
following is from INDY smtpserver sample
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;
what do i have to add to this project to work as email sending server.
I haven't done many changes to the original sample(only for compatibility) as i can't understand most of the concepts behind how email is sent and received. please explain me how to make this code to send email to the destination(eg: [email protected]) given in this question Indy Mail server (smtpclient),
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
要将电子邮件传递到另一个系统(在本例中为 Gmail),请使用
TIdSMTPRelay
组件,例如:To pass the email on to another system (Gmail in this case), use the
TIdSMTPRelay
component, eg: