procedure
mail;
var
smtp : TIdSMTP;
msg : TIdMessage;
attach: TidAttachment;
fi : System
.
Text;
text :
string
;
begin
AssignFile(fi,
'C:\file.txt'
);
Reset(fi);
smtp := TIdSMTP
.
Create(
nil
);
smtp
.
AuthenticationType := atLogin;
smtp
.
Username :=
'username'
;
smtp
.
Password :=
'password'
;
smtp
.
Host :=
'smtp.yandex.ru'
;
smtp
.
Port :=
25
;
smtp
.
Connect;
if
smtp
.
Authenticate
then
begin
msg := TIdMessage
.
Create(
nil
);
msg
.
Subject :=
'subject'
;
msg
.
Body
.
Add(
'Attachement file:'
);
msg
.
From
.
Text :=
'xxx@yandex.ru'
;
msg
.
Recipients
.
EMailAddresses := <a href="mailto:xxx@yandex
.
ru">xxx@yandex
.
ru</a>';
while
not
eof(fi)
do
begin
while
not
eoln(fi)
do
begin
read (fi, text);
end
;
end
;
attach:=TIdAttachment
.
Create(msg
.
MessageParts, TFileName(text));
smtp
.
Send(msg);
smtp
.
Disconnect;
msg
.
Free;
end
;
smtp
.
Free;
CloseFile(fi);
end
;