tôi cố gắng để gửi một email, nhưng tôi có một vấn đề, tuy nhiên, tôi tìm thấy mã này trên trang web:SendEmail với các thành phần Indy
Uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, IdMessage, IdTCPConnection, IdTCPClient,
IdMessageClient, IdSMTP, IdBaseComponent, IdComponent, IdIOHandler,
IdExplicitTLSClientServerBase, IdSMTPBase
procedure SendSimpleMail;
var
Msg: TIdMessage;
DestAddr: TIdEmailAddressItem;
begin
Msg := TIdMessage.Create(Self); //error here
Msg.From.Text := 'name';
Msg.From.Address := '[email protected]';
Msg.Subject := 'Test';
DestAddr := Msg.Recipients.Add;
DestAddr.Text := 'name';
DestAddr.Address := '[email protected]';
Msg.Body.Add('simple test mail.');
tIdSMTP.Host := 'smtp.gmail.com';
tIdSMTP.Port := 25;
tIdSMTP.AuthenticationType := atLogin; //error here (2 error)
tIdSMTP.Username := '[email protected]';
tIdSMTP.Password := 'password';
tIdSMTP.Connect;
tIdSMTP.Authenticate;
tIdSMTP.Send(Msg);
tIdSMTP.Disconnect;
end;
Nhưng tuy nhiên, tôi ghi nhận nhiều sai lầm và tôi đang thiếu một thành phần của Indy. lỗi biên dịch:
[DCC Error] Unit1.pas(36): E2003 Undeclared identifier: 'Self'
[DCC Error] Unit1.pas(46): E2233 Property 'Host' inaccessible here
[DCC Error] Unit1.pas(47): E2233 Property 'Port' inaccessible here
[DCC Error] Unit1.pas(48): E2003 Undeclared identifier: 'AuthenticationType'
[DCC Error] Unit1.pas(48): E2003 Undeclared identifier: 'atLogin'
[DCC Error] Unit1.pas(49): E2233 Property 'Username' inaccessible here
[DCC Error] Unit1.pas(50): E2233 Property 'Password' inaccessible here
[DCC Error] Unit1.pas(51): E2076 This form of method call only allowed for class methods
[DCC Error] Unit1.pas(52): E2076 This form of method call only allowed for class methods
[DCC Error] Unit1.pas(53): E2076 This form of method call only allowed for class methods
[DCC Error] Unit1.pas(54): E2076 This form of method call only allowed for class methods
[DCC Error] Project1.dpr(5): F2063 Could not compile used unit 'Unit1.pas'
Thanks for the help trước
Một điều là thêm 'IdEMailAddress' quy định tại khoản sử dụng của bạn để làm cho trình biên dịch biết' TIdEmailAddressItem' , nhưng khác là ví dụ về cơ bản là sai và nó cho Indy 9 (vì kiểu xác thực 'atLogin'), bạn đang sử dụng phiên bản Indy nào? Bạn có thể kiểm tra xem bạn có giữ phím 'CTRL' không và nhấp vào ví dụ: 'IdSMTP' từ mệnh đề sử dụng của bạn và sau đó kiểm tra vị trí' IdSMTP.pas' được lưu trữ. Nếu nó nằm trong thư mục 'Indy9' hoặc' Indy10'. – TLama
ok cảm ơn, bây giờ các lỗi được giảm, nhưng bây giờ là 3 lỗi (tôi đã chỉnh sửa bài đầu tiên), tôi có Indy9 và Indy10, nhưng khi tôi bấm vào idSMTP tôi nhận được một lỗi: Không thể xác định vị trí tập tin idSMTP.pas –