I want to send mails with SendSmtpMail. But I always get "false" as the result.
Code: Select all
var FileNames : TStringDynArray := Utils.GetFiles(gConstData.ExchangeFolder, faAnyFile, 0, '*.txt');
for var i : Integer := 0 to High(FileNames) do begin
var SL := TStringList.Create;
var MailFrom, MailSubject, MailAddr, MailBody, SmtpServer, SmtpPassword : string;
var SmtpPort : Integer;
var FileName : string := FileNames[i];
SL.LoadFromFile(FileName);
for var j : Integer := 0 to Pred(SL.Count) do
Log.Debug('[%d]: [%s]', [j, SL[j]]);
MailFrom := gConstData.AMMailIniFile.ReadString(sPaths, 'MailFrom', '');
SmtpServer := gConstData.AMMailIniFile.ReadString(sPaths, 'SmtpServer', '');
SmtpPassword := gConstData.AMMailIniFile.ReadString(sPaths, 'SmtpPassword', '');
SmtpPort := gConstData.AMMailIniFile.ReadInteger(sPaths, 'SmtpPort', 0);
MailSubject := SL[0];
MailSubject := 'Betreff'; // Debug ###############
MailAddr := SL[1];
MailAddr := 'status@example.org'; // Debug ###############
MailBody := StringReplace(SL[9], '#13#10#', sLineBreak, [rfReplaceAll]);
MailBody := 'Body'; // Debug ###############
Log.Debug('MailFrom: [%s]', [MailFrom]);
Log.Debug('MailAddr: [%s]', [MailAddr]);
Log.Debug('MailSubject: [%s]', [MailSubject]);
Log.Debug('MailBody: [%s]', [MailBody]);
Log.Debug('SmtpServer: [%s]', [SmtpServer]);
// Log.Debug('SmtpPassword: [%s]', [SmtpPassword]);
Log.Debug('SmtpPort: [%d]', [SmtpPort]);
Log.Info(Format('Send Mail [%s] from [%s] to [%s]; SmtpServer [%s]; SmtpPort [%d]',
[MailSubject, MailFrom, MailAddr, SmtpServer, SmtpPort]));
if not SendSmtpMail(
MailFrom,
MailAddr,
'', // replyTo
MailSubject,
MailBody,
nil, // attachments
SmtpServer,
'', // authUserName
SmtpPassword, // authPassword
SmtpPort, // port
True, // ssl
True, // tls
0, // parentWindow
false, // hidden
false, // background
nil) then begin // settings
Log.Error('Error sending mail!');
end;
I'm not sure what to do with the last parameter „settings“?
I'm using this in a windows service, so there is no GUI, but that should make no difference. TIA, Markus