const
atNoLogin = 0;
atSimpleLogin = 1;
procedure Sendemail(sender_email, recipent_email, email_subject:
string;
email_text: tstrings; attachment_list: tstrings;
//can be also attachment_list: tstringlist;
smtp_username, smtp_password, smtp_host:
string;
const SmtpAuthType: integer = atSimpleLogin;
smtp_port: integer = 25;
email_priority: integer = 2);
var
idmsgSend: Tidmessage;
smtp: Tidsmtp;
i: integer;
begin
idmsgSend := Tidmessage.Create(
nil);
smtp := Tidsmtp.Create(
nil);
try
with IdMsgSend
do
begin
Body.Assign(email_text);
From.Text := sender_email;
ReplyTo.EMailAddresses := sender_email;
Recipients.EMailAddresses := recipent_email;
{ To: header }
Subject := email_subject;
{ Subject: header }
Priority := TIdMessagePriority(email_priority);
{ Message Priority }
CCList.EMailAddresses := '
';
{CC}
BccList.EMailAddresses := '
';
{BBC}
ReceiptRecipient.Text := '
';
end;
{attachment settings}
if assigned(attachment_list)
then
for i := 0
to attachment_list.Count - 1
do
TIdAttachment.Create(IdMsgSend.MessageParts, attachment_list.Strings[i]);
{authentication settings}
case SmtpAuthType
of
0:
SMTP.AuthenticationType := atNone;
1:
SMTP.AuthenticationType := atLogin;
{Simple Login}
end;
SMTP.Username := smtp_username;
SMTP.Password := smtp_password;
{General setup}
SMTP.Host := smtp_host;
SMTP.Port := smtp_port;
{now we send the message}
SMTP.Connect;
try
SMTP.Send(IdMsgSend);
finally
SMTP.Disconnect;
end;
finally
idmsgSend.free;
smtp.free;
end;
end;