unit Mail;
interface
uses
Winapi.Windows,
Winapi.Messages, System.SysUtils, System.Variants, System.Classes,
Vcl.Graphics,
Vcl.Controls,
Vcl.Forms,
Vcl.Dialogs, IdIOHandler, IdIOHandlerSocket,
IdIOHandlerStack, IdSSL, IdSSLOpenSSL, IdBaseComponent, IdComponent,
IdTCPConnection, IdTCPClient, IdExplicitTLSClientServerBase, IdMessageClient,
IdSMTPBase, IdSMTP, IdMessage, IdAttachment, IdAttachmentFile;
type
TForm2 =
class(TForm)
IdSMTP: TIdSMTP;
IdSSLIOHandlerSocketOpenSSL: TIdSSLIOHandlerSocketOpenSSL;
IdMessage: TIdMessage;
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
Function SendMail(Absender:
string; Empfänger:
string; Betreff:
String; Nachricht:TStringList; Anhang:TStringlist):Boolean;
end;
var
Form2: TForm2;
implementation
{$R *.dfm}
Function TForm2.SendMail(Absender:
string; Empfänger:
string; Betreff:
string; Nachricht: TStringlist; Anhang: TStringlist): Boolean;
var
Mes:TIdMessage;
Attachment:TIdAttachment;
i:integer;
begin
Mes:=TIdMessage.Create(self);
try
begin
with Mes
do
begin
Clear;
ContentType:='
multipart/*';
From.Address:=Absender;
Recipients.EMailAddresses:=Empfänger;
Subject:=Betreff;
Body:=Nachricht;
if Anhang.Count <> 0
then
begin
for i := 0
to Anhang.Count-1
do
begin
Attachment:=TIdAttachmentFile.Create(Mes.MessageParts,Anhang[i]);
end;
end;
end;
if IdSMTP.Connected
then IdSMTP.Disconnect;
IdSMTP.Port:=587;
IdSMTP.UseTLS:=utUseExplicitTLS;
IdSMTP.Host:=******@****.de;
IdSMTP.Username:=*********;
IdSMTP.Password:=********************;
IdSMTP.AuthType:=TIdSMTPAuthenticationType.satDefault;
IdSMTP.ConnectTimeout:=1000;
IdSMTP.Connect;
IdSMTP.Authenticate;
try
begin
IdSMTP.Send(Mes);
result:=true;
end;
except
begin
result:=false;
end;
end;
end;
finally
begin
IdSMTP.Disconnect;
Attachment.Free;
Mes.Free;
end;
end;
end;
end.