15 TAuthenticationType
= (atNone
, atLogin
);
18 ID_TIDSMTP_AUTH_TYPE
= atNone
;
21 TIdSMTP
= object(TIdMessageClient
)
23 FDidAuthenticate
: Boolean;
24 FAuthenticationType
: TAuthenticationType
;
29 procedure GetAuthTypes
;
30 function IsAuthProtocolAvailable(Auth
: TAuthenticationType
)
33 AuthSchemesSupported
: PStrList
;
35 procedure Assign(Source
: {TPersistent}PObj
); virtual;//override;
36 function Authenticate
: Boolean; virtual;
37 procedure Connect
; virtual;//override;
38 { constructor Create(AOwner: TComponent); override;
40 virtual; procedure Disconnect
; virtual;//override;
41 { object (TObj)}procedure QuickSend(const AHost
, ASubject
, ATo
,
42 AFrom
, AText
: string);
43 procedure Send(AMsg
: PIdMessage
); virtual;
45 // property AuthSchemesSupported: TStringList read FAuthSchemesSupported;
47 property AuthenticationType
: TAuthenticationType read FAuthenticationType
48 write FAuthenticationType default ID_TIDSMTP_AUTH_TYPE
;
49 property MailAgent
: string read FMailAgent write FMailAgent
;
50 property Password
: string read FPassword write FPassword
;
51 property UserId
: string read FUserId write FUserId
;
52 //property Port default IdPORT_SMTP;
55 function NewIdSMTP(AOwner
: {TComponent}PControl
):PIdSMTP
;
63 procedure TIdSMTP
.Assign(Source
: {TPersistent}Pobj
);
65 { if Source is TIdSMTP then
67 AuthenticationType := TIdSMTP(Source).AuthenticationType;
68 Host := TIdSMTP(Source).Host;
69 MailAgent := TIdSMTP(Source).MailAgent;
70 Password := TIdSMTP(Source).Password;
71 Port := TIdSMTP(Source).Port;
72 UserId := TIdSMTP(Source).UserId;
78 function TIdSMTP
.Authenticate
: Boolean;
80 function AuthLogin
: Boolean;
82 SendCmd('auth LOGIN', 334); {Do not localize}
83 SendCmd(Base64Encode(UserId
), 334);
84 SendCmd(Base64Encode(Password
), 235);
90 case FAUthenticationType
of
91 atLogin
: Result
:= AuthLogin
;
93 FDidAuthenticate
:= True;
96 procedure TIdSMTP
.Connect
;
101 AuthSchemesSupported
.Clear
;
102 if SendCmd('ehlo ' + LocalName
) = 250 then {Do not localize}
108 SendCmd('Helo ' + LocalName
, 250); {Do not localize}
116 //constructor TIdSMTP.Create(AOwner: TComponent);
117 function NewIdSMTP(AOwner
: PControl
):PIdSMTP
;
119 New( Result
, Create
);
123 AuthSchemesSupported
:= NewStrList
;
128 destructor TIdSMTP
.Destroy
;
130 // FreeAndNil(FAuthSchemesSupported);
134 procedure TIdSMTP
.Disconnect
;
139 WriteLn('Quit'); {Do not localize}
143 FDidAuthenticate
:= False;
147 procedure TIdSMTP
.GetAuthTypes
;
154 while Iterator
< FCmdResultDetails
.Count
do
156 // Buffer := UpperCase(FCmdResultDetails[Iterator]);
157 if (IndyPos('AUTH', Buffer
) = 5) and ((Copy(Buffer
, 9, 1) = ' ') or
159 (Copy(Buffer
, 9, 1) = '=')) then {Do not localize}
161 Buffer
:= Copy(Buffer
, 10, Length(Buffer
));
162 while Buffer
<> '' do
164 while StrReplace(Buffer
, '=', ' ') do; {Do not localize}
165 ListEntry
:= Fetch(Buffer
, ' '); {Do not localize}
166 // if (FAuthSchemesSupported.IndexOf(ListEntry) = -1) then
167 // FAuthSchemesSupported.Add(ListEntry);
174 function TIdSMTP
.IsAuthProtocolAvailable(
175 Auth
: TAuthenticationType
): Boolean;
178 atLogin: Result := (FAuthSchemesSupported.IndexOf('LOGIN') <> -1);
185 {class} procedure TIdSMTP
.QuickSend(const AHost
, ASubject
, ATo
,
186 AFrom
, AText
: string);
191 (* SMTP := TIdSMTP.Create(nil);
193 Msg := TIdMessage.Create(SMTP);
197 Recipients.EMailAddresses := ATo;
217 procedure TIdSMTP
.Send(AMsg
: PIdMessage
);
219 procedure WriteRecipient(const AEmailAddress
: pIdEmailAddressItem
);
221 SendCmd('RCPT to:<' + AEMailAddress
.Address
+ '>', 250); {Do not localize}
224 procedure WriteRecipients(AList
: pIdEmailAddressList
);
228 for i
:= 0 to AList
.count
- 1 do
230 WriteRecipient(AList
.Items
[i
]);
234 function NeedToAuthenticate
: Boolean;
236 if FAuthenticationType
<> atNone
then
238 Result
:= IsAuthProtocolAvailable(FAuthenticationType
)
239 and (FDidAuthenticate
= False);
248 SendCmd('Rset'); {Do not localize}
249 if NeedToAuthenticate
then
253 SendCmd('Mail from:<' + AMsg
.From
.Address
+ '>', 250); {Do not localize}
254 WriteRecipients(AMsg
.Recipients
);
255 WriteRecipients(AMsg
.CCList
);
256 WriteRecipients(AMsg
.BccList
);
257 SendCmd('Data', 354); {Do not localize}
258 AMsg
.ExtraHeaders
.Values
['X-Mailer'] := MailAgent
; {Do not localize}
260 SendCmd('.', 250); {Do not localize}