function PostMock(ASource: TIdStrings):
String;
var
MailMessage: TIdMessage;
_receiver,
_subject,
_bodycontent:
String;
begin
// Wenn cbSSLMails gecheckt ist, dann wird die Mail mit SSL verschickt.
with Form1
do begin
IdSMTP1.Host := mail_host;
IdSMTP1.Port := StrToInt(mail_port);
IdSMTP1.Username :=
{Benutzername};
IdSMTP1.Password :=
{Passwort};
_receiver := ASource.Values ['
receiver'];
_subject := ASource.Values ['
subject'];
_bodycontent := ASource.Values ['
bodycontent'];
if cbSSLMails.Checked
then begin // SSL konfigurieren
with IdSSLIOHandlerSocketOpenSSL1
do begin
MaxLineAction := maException;
with SSLOptions
do begin
Method := sslvSSLv3;
//sslvTLSv1;
Mode := sslmUnassigned;
VerifyMode := [];
VerifyDepth := 0;
PassThrough := false;
end;
end;
IdSMTP1.IOHandler := IdSSLIOHandlerSocketOpenSSL1;
IdSMTP1.UseTLS := utUseImplicitTLS;
// für Port 465 (bereits das Greeting ist verschlüsselt)
end;
MailMessage := TIdMessage.Create(
nil);
try
with MailMessage
do begin
Recipients.Clear;
From.
Name :=
{From-Name};
From.Address := IdSMTP1.Username;
ReplyTo.EMailAddresses :=
{Adresse};
Recipients.EMailAddresses := _receiver;
Date := now;
Subject := _subject;
Body.Text := _bodycontent;
end;
IdSMTP1.AuthType := atDefault;
//atDefault; // (atNone, atDefault, atSASL) // atDefault ist wahrscheinlich atLogin
IdSMTP1.Connect;
Fred.MailSent := false;
IdSMTP1.Send(MailMessage);
Repeat
Application.ProcessMessages;
until Fred.MailSent;
if IdSMTP1.Connected
then IdSMTP1.Disconnect;
FreeAndNil(MailMessage);
Result := '
Success';
except on e:
Exception do begin
FreeAndNil(MailMessage);
Result := '
Mail delivery failed ('+e.
Message+'
).';
end;
end;
end;
end;