dsRESTConnection component won't allow me change the .username and .password after the first connect - rest

In my Delphi 10.3.1 application server (which is a "DataSnap REST Application"), I have put some logging as follows:
procedure TWebModule1.DSAuthenticationManager1UserAuthenticate(
Sender: TObject; const Protocol, Context, User, Password: string;
var valid: Boolean; UserRoles: TStrings);
begin
valid := (User > '') and (Password > ''); // pass-through
if Valid then
begin
MyWebUtils.LogMessage('Authentication, ' + User + ', ' + Password +
', ' + protocol + ', ' + context);
TDSSessionManager.GetThreadSession.PutData('USERNAME', User);
end;
end;
In my client (on Android), which uses a dsRestConnection, I have a procedure to test the connection, which I call, for example in FormShow of the main form.
function TClientModuleRest.TestConnect(var ErrorMsg: String): Boolean;
var
returned: String;
begin
Result := True;
try
DSRestConnection.Username := 'Admin';
DSRestConnection.Password := 'Test';
DSRestConnection.TestConnection([toNoLoginPrompt]);
except
on e: exception do
begin
Result := False;
ErrorMsg := e.Message;
end
end;
end;
This works well.
The problem occurs when I call the first Server method.
function TClientModuleRest.ValidUser(username, password: String;
var Response: String): Integer;
var
Server: TServerMethodsRClient;
Valid: Boolean;
IniFile: TStringList;
FileName: TFileName;
begin
Result := 0;
DSRestConnection.UserName := username;
DSRestConnection.Password := password;
try
Server := TServerMethodsRClient.Create(DSRestConnection);
try
Valid := Server.ValidUser(username, password, Response);
if not Valid then
raise Exception.Create(response);
Result := 1;
finally
Server.Free;
end;
except
on e: exception do
begin
Response := e.Message;
Result := -1; // an error occured
end;
end;
end;
So the problem is that the setting of the .username and .password doesn't 'take'. In other words, my conclusion is that the .username and `.password can only be set before the first connect, and not thereafter.
The server log file shows that even though the ValidUser function was called with the username and password values that were passed to it, the authentication is receiving the username and password from the first (test) connect.
Is this by design? Or am I missing something? Thanks.

Related

Custom command line parameter - distinguish nonexistence from blank? [duplicate]

I am new to Inno Setup and I have already read the documentation. Now I know that Inno Setup can accept different/custom parameter and could be processed via Pascal script. But the problem is, I don't know how to write in Pascal.
I am hoping I could get help about the coding.
I'd like to pass /NOSTART parameter to my setup file which while tell the setup to disable(uncheck) the check mark on "Launch " and if /NOSTART is not provided, it it will enable(check) the check mark "Launch "
or if possible, that Launch page is not required and do everything via code.
Since you can't imperatively modify flags for section entries and directly accessing the RunList would be quite a dirty workaround, I'm using for this two postinstall entries, while one has no unchecked flag specified and the second one has. So, the first entry represents the checked launch check box and the second one unchecked launch check box. Which one is used is controlled by the Check parameter function, where is checked if a command line tail contains /NOSTART parameter.
Also, I've used a little more straightforward function for determining if a certain parameter is contained in the command line tail. It uses the CompareText function to compare text in a case insensitive way. You can replace it with CompareStr function, if you want to compare the parameter text in a case sensitive way. Here is the script:
[Setup]
AppName=My Program
AppVersion=1.5
DefaultDirName={pf}\My Program
OutputDir=userdocs:Inno Setup Examples Output
[Run]
Filename: "calc.exe"; Description: "Launch calculator"; \
Flags: postinstall nowait skipifsilent; Check: LaunchChecked
Filename: "calc.exe"; Description: "Launch calculator"; \
Flags: postinstall nowait skipifsilent unchecked; Check: not LaunchChecked
[Code]
function CmdLineParamExists(const Value: string): Boolean;
var
I: Integer;
begin
Result := False;
for I := 1 to ParamCount do
if CompareText(ParamStr(I), Value) = 0 then
begin
Result := True;
Exit;
end;
end;
function LaunchChecked: Boolean;
begin
Result := not CmdLineParamExists('/NOSTART');
end;
and so a little research read and read .. i got my answer.
here's my code (except the "GetCommandLineParam")
[Code]
{
var
StartNow: Boolean;
}
function GetCommandLineParam(inParam: String): String;
var
LoopVar : Integer;
BreakLoop : Boolean;
begin
{ Init the variable to known values }
LoopVar :=0;
Result := '';
BreakLoop := False;
{ Loop through the passed in arry to find the parameter }
while ( (LoopVar < ParamCount) and
(not BreakLoop) ) do
begin
{ Determine if the looked for parameter is the next value }
if ( (ParamStr(LoopVar) = inParam) and
( (LoopVar+1) <= ParamCount )) then
begin
{ Set the return result equal to the next command line parameter }
Result := ParamStr(LoopVar+1);
{ Break the loop }
BreakLoop := True;
end;
{ Increment the loop variable }
LoopVar := LoopVar + 1;
end;
end;
{
function InitializeSetup(): Boolean;
var
NOSTART_Value : String;
begin
NOSTART_Value := GetCommandLineParam('/NOSTART');
if(NOSTART_Value = 'false') then
begin
StartNow := True
end
else
begin
StartNow := False
end;
Result := True;
end;
}
procedure CurStepChanged(CurStep: TSetupStep);
var
Filename: String;
ResultCode: Integer;
NOSTART_Value : String;
begin
if CurStep = ssDone then
begin
NOSTART_Value := GetCommandLineParam('/NOSTART');
if(NOSTART_Value = 'false') then
begin
Filename := ExpandConstant('{app}\{#MyAppExeName}');
Exec(Filename, '', '', SW_SHOW, ewNoWait, Resultcode);
end
end;
end;
a code update. Thanks to #TLama
function CmdLineParamExists(const Value: string): Boolean;
var
I: Integer;
begin
Result := False;
for I := 1 to ParamCount do
if CompareText(ParamStr(I), Value) = 0 then
begin
Result := True;
Break;
end;
end;
procedure CurStepChanged(CurStep: TSetupStep);
var
Filename: String;
ResultCode: Integer;
NOSTART_Value : String;
RunApp : Boolean;
begin
if CurStep = ssDone then
begin
RunApp := CmdLineParamExists('/START');
if(RunApp = True) then
begin
Filename := ExpandConstant('{app}\{#MyAppExeName}');
Exec(Filename, '', '', SW_SHOW, ewNoWait, Resultcode);
end
// NOSTART_Value := GetCommandLineParam('/START');
// if(NOSTART_Value = 'true') then
// begin
// Filename := ExpandConstant('{app}\{#MyAppExeName}');
// Exec(Filename, '', '', SW_SHOW, ewNoWait, Resultcode);
//end
end;
end;
How about the following, easy to read
; Script generated by the Inno Script Studio Wizard.
; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES!
#define MyAppName "Install Specialty Programs"
#define MyAppVersion "1.0"
#define MyAppPublisher ""
[Setup]
; NOTE: The value of AppId uniquely identifies this application.
; Do not use the same AppId value in installers for other applications.
; (To generate a new GUID, click Tools | Generate GUID inside the IDE.)
AppId={{5}
AppName={#MyAppName}
AppVersion={#MyAppVersion}
;AppVerName={#MyAppName} {#MyAppVersion}
AppPublisher={#MyAppPublisher}
DefaultDirName={pf}\{#MyAppName}
DisableDirPage=yes
DefaultGroupName={#MyAppName}
DisableProgramGroupPage=yes
OutputDir=P:\_Development\INNO Setup Files\Specialty File Install
OutputBaseFilename=Specialty File Install
Compression=lzma
SolidCompression=yes
[Languages]
Name: "english"; MessagesFile: "compiler:Default.isl"
[Files]
Source: "P:\_Development\INNO Setup Files\Specialty File Install\Files\0.0 - Steps.docx"; DestDir: "c:\support\Specialty Files"; Tasks: V00Step
[Tasks]
Name: "Office2013"; Description: "Running Office 2013"; Flags: checkablealone unchecked
Name: "Office2016"; Description: "Running Office 2016"; Flags: checkablealone unchecked
Name: "V00Step"; Description: "Steps To Follow (Read Me)"; Flags: exclusive
[Run]
Filename: "C:\Program Files (x86)\Microsoft Office\Office15\WINWORD.EXE"; Parameters: """c:\support\Specialty Files\0.0 - Steps.docx"""; Description: "Run if Office 2013 is installed"; Tasks: V00Step AND Office2013
Filename: "C:\Program Files (x86)\Microsoft Office\Office16\WINWORD.EXE"; Parameters: """c:\support\Specialty Files\0.0 - Steps.docx"""; Description: "Run if Office 2016 is installed"; Tasks: V00Step AND Office2016

Sending an Email in Delphi using Indy... SSL Negotiation Failed [duplicate]

I try to send eMail with the code below (taken from http://delphiprogrammingdiary.blogspot.com/2014/12/how-to-send-email-in-delphi.html) without success.
Constantly I receive the error ("socket error 10054 connection reset by peer" twice and finally "SSL negotiation failed") at the statement "Send(IdMessage1)" although client is successfully connected with server.
procedure SendEmailClick(Sender: TObject);
var
IdMessage1: TIdMessage;
Attachmentfile: TIdAttachmentFile;
begin
// IO HANDLER SETTINGS //
With TIdSSLIOHandlerSocketOpenSSL.Create(nil) do
begin
Destination := 'mySrver.com:587';
Host := 'mySrver.com';
MaxLineAction := maException;
Port := 587;
SSLOptions.SSLVersions := [sslvTLSv1, sslvTLSv1_1, sslvTLSv1_2];
SSLOptions.Mode := sslmUnassigned;
SSLOptions.VerifyMode := [];
SSLOptions.VerifyDepth := 0;
end;
//SETTING SMTP COMPONENT DATA //
with TIdSMTP.Create(nil) do begin
Host := 'mySrver.com';
Port := 587;
Username := myMailAddress; // please change to your gmail address //
Password := myPassword;
IOHandler := TIdSSLIOHandlerSocketOpenSSL.create;
AuthType := satDefault;
UseTLS := utUseExplicitTLS;
// SETTING email MESSAGE DATA //
IdMessage1:= TIdMessage.Create(nil);
IdMessage1.Clear;
// add recipient list //
with IdMessage1.Recipients.Add do
begin
Name := 'Recipient 1';
Address := recipient1Address; // please change email address as required //
end;
//add Attachment to mail //
Attachmentfile := TIdAttachmentFile.Create(IdMessage1.MessageParts,'Τιμολόγιο 659.PDF');
IdMessage1:= TIdMessage.Create(nil);
IdMessage1.From.Address := myMailAddress; // please change to your gmail address //;
IdMessage1.Subject := 'Test Email Subject';
IdMessage1.Body.Add('Test Email Body');
IdMessage1.Priority := mpHigh;
TRY
Connect(); // no problem here. it connects always
Send(IdMessage1); // raises the error SSL negotiation failed
ShowMessage('Email sent');
Disconnect();
except on e:Exception do
begin
ShowMessage(e.Message);
Disconnect();
end;
END;
IdMessage1.Free;
IOHandler.Free;
end;
AttachmentFile.Free;
end;
Can you help me please ?
PS1. The same problem raises with any MAPI server (myServer, GMail, Yahoo etc)
PS2. The SSL DLLs are present and they are used by the same application to connect for other purpose without this problem.
You are creating a TIdSSLIOHandlerSocketOpenSSL object and configuring it, but then you discard and leak it and then create and use another TIdSSLIOHandlerSocketOpenSSL object with default settings. Get rid of the second object, use the first object instead.
You are also creating 2 TIdMessage objects, as well. Get rid of the second one.
Also, you don't need to set the Host, Port, and Destination properties on the SSLIOHandler. Connect() will handle that for you.
Try this:
procedure SendEmailClick(Sender: TObject);
var
IdSMTP: TIdSMTP;
IdMessage1: TIdMessage;
Attachmentfile: TIdAttachmentFile;
IdSSL: TIdSSLIOHandlerSocketOpenSSL;
begin
//SETTING SMTP COMPONENT DATA //
IdSMTP := TIdSMTP.Create(nil);
try
IdSMTP.Host := 'mySrver.com';
IdSMTP.Port := 587;
IdSMTP.Username := myMailAddress; // please change to your gmail address
// Password := myPassword;
IdSMTP.AuthType := satDefault;
IdSMTP.UseTLS := utUseExplicitTLS;
// IO HANDLER Settings //
IdSSL := TIdSSLIOHandlerSocketOpenSSL.Create(IdSMTP);
IdSSL.SSLOptions.SSLVersions := [sslvTLSv1, sslvTLSv1_1, sslvTLSv1_2];
IdSSL.SSLOptions.Mode := sslmUnassigned;
IdSSL.SSLOptions.VerifyMode := [];
IdSSL.SSLOptions.VerifyDepth := 0;
IdSMTP.IOHandler := IdSSL;
// SETTING email MESSAGE DATA //
IdMessage1 := TIdMessage.Create(nil);
try
// add recipient list //
with IdMessage1.Recipients.Add do
begin
Name := 'Recipient 1';
Address := recipient1Address; // please change email address as required //
end;
//add Attachment to mail //
Attachmentfile := TIdAttachmentFile.Create(IdMessage1.MessageParts, 'Τιμολόγιο 659.PDF');
IdMessage1.From.Address := myMailAddress; // please change to your gmail address //;
IdMessage1.Subject := 'Test Email Subject';
IdMessage1.Body.Add('Test Email Body');
IdMessage1.Priority := mpHigh;
try
IdSMTP.Connect();
try
IdSMTP.Send(IdMessage1);
ShowMessage('Email sent');
finally
IdSMTP.Disconnect();
end;
except
on e: Exception do
begin
ShowMessage(e.Message);
end;
end;
finally
IdMessage1.Free;
end;
finally
IdSMTP.Free;
end;
end;

How to post data with a ContentType of 'multipart/form-data' in Delphi REST?

I am trying to send a request to a REST API using multipart/form-data as the content type.
I always get "HTTP/1.1 500 Internal Error" as a response.
I tried sending requests to methods that require application/x-www-form-urlencoded and had success, though.
How can I achieve getting a success response from my API using multipart/form-data?
Here is my code:
procedure TForm10.Button1Click(Sender: TObject);
var
RESTClient1: TRESTClient;
RESTRequest1: TRESTRequest;
strImageJSON : string;
Input: TIdMultipartFormDataStream;
begin
Input := TIdMultipartFormDataStream.Create;
Input.Clear;
Input.AddFormField('Email', 'tugba.xx#allianz.com.tr');
Input.AddFormField('Password', 'xxxx');
RESTClient1 := TRESTClient.Create('http://192.168.1.172:81/');
RESTRequest1 := TRESTRequest.Create(nil);
RESTRequest1.Method := TRESTRequestMethod.rmPOST;
RESTRequest1.Resource := 'api/Mobile/MobileLoginControl';
RESTRequest1.AddBody(Input,TRESTContentType.ctMULTIPART_FORM_DATA);
RESTRequest1.Client := RESTClient1;
RESTRequest1.Execute;
strImageJSON := RESTRequest1.Response.Content;
end;
Embarcadero's REST component has its own built in multipart/form-data capabilities via the TRESTRequest.AddParameter() method:
procedure TForm10.Button1Click(Sender: TObject);
var
RESTClient1: TRESTClient;
RESTRequest1: TRESTRequest;
strImageJSON : string;
begin
RESTClient1 := TRESTClient.Create('http://192.168.1.172:81/');
try
RESTRequest1 := TRESTRequest.Create(nil);
try
RESTRequest1.Method := TRESTRequestMethod.rmPOST;
RESTRequest1.Resource := 'api/Mobile/MobileLoginControl';
RESTRequest1.AddParameter('Email', 'tugba.xx#allianz.com.tr', TRESTRequestParameterKind.pkREQUESTBODY);
RESTRequest1.AddParameter('Password', 'xxxx', TRESTRequestParameterKind.pkREQUESTBODY);
RESTRequest1.Client := RESTClient1;
RESTRequest1.Execute;
strImageJSON := RESTRequest1.Response.Content;
finally
RESTRequest1.Free;
end;
finally
RESTClient1.Free;
end;
end;
You don't need to use use Indy's TIdMultiPartFormDataStream, especially when you are not using Indy's TIdHTTP.

Sending e-mail with attachments with Indy

First of all, code.
procedure TMain.SendEmailIndy(
const SMTPServer: string;
const FromName, FromAddress: string;
const ToAddresses: string; //comma "," separated list of e-mail addresses
const CCAddresses: string; //comma "," separated list of e-mail addresses
const BCCAddresses: string; //comma "," separated list of e-mail addresses
const Subject: string;
const EmailBody: string;
const IsBodyHtml: Boolean);
var
smtp: TIdSMTP; // IdSmtp.pas
msg: TidMessage; // IdMessage.pas
builder: TIdCustomMessageBuilder; //IdMessageBuilder.pas
s: string;
emailAddress: string;
FileToSend: TIdAttachmentfile;
begin
msg := TidMessage.Create(nil);
try
if IsBodyHtml then begin
builder := TIdMessageBuilderHtml.Create;
TIdMessageBuilderHtml(builder).Html.Text := EmailBody
end else begin
builder := TIdMessageBuilderPlain.Create;
end;
if (Realization.AttachmentD.FileName <> '') then begin
msg.IsEncoded := true;
FileToSend := TIdAttachmentFile.Create(msg.MessageParts, Realization.AttachmentD.FileName);
FileToSend.FileName := Realization.AttachmentD.FileName;
//FileToSend.ContentDisposition := 'attachment';
FileToSend.ContentType := 'multipart/mixed';
ShowMessage('Sent: '+Realization.AttachmentD.FileName);
end;
msg.From.Name := FromName;
msg.From.Address := FromAddress;
msg.Subject := Subject;
//If the message is plaintext then we must fill the body outside of the PlainText email builder.
//(the PlainTextBuilder is unable to build plaintext e-mail)
if not IsBodyHtml then begin
msg.Body.Text := EmailBody;
end;
for s in ToAddresses.Split([',']) do
begin
emailAddress := Trim(s);
if emailAddress <> '' then begin
with msg.recipients.Add do
begin
//Name := '<Name of recipient>';
Address := emailAddress;
end;
end;
end;
for s in CCAddresses.Split([',']) do
begin
emailAddress := Trim(s);
if emailAddress <> '' then
msg.CCList.Add.Address := emailAddress;
end;
for s in BCCAddresses.Split([',']) do
begin
emailAddress := Trim(s);
if emailAddress <> '' then
msg.BccList.Add.Address := emailAddress;
end;
smtp := TIdSMTP.Create(nil);
try
msg.Encoding := meMIME;
msg.ContentType := 'text/html';
msg.CharSet := 'UTF-8';
msg.ContentTransferEncoding:= 'quoted-printable';
smtp.Host := SMTPServer; // IP Address of SMTP server
Smtp.UseTLS := utNoTLSSupport;
smtp.Port := 587; //The default already is port 25 (the SMTP port)
smtp.Username := _GlobalData.EMail;
smtp.Password := _GlobalData.Password;
smtp.Connect;
try
smtp.Send(msg);
ShowMessage('Wiadomość wysłana.');
Realization.AttachmentD.FileName := '';
finally
smtp.Disconnect();
end;
finally
smtp.Free;
end;
finally
msg.Free;
end;
end;
I experience problems with sending e-mail message with attached file to it.
When I remove the following line from the code above, the message is sent without html message (e-mail body) that should be there:
FileToSend.ContentType := 'multipart/mixed';
However, when I leave this line in the code and try to send a message, I receive this message:
A policy-violation was found in an Email message you sent.
This Email scanner intercepted it and stopped the entire message
reaching its destination.
The policy-violation was reported to be:
Disallowed breakage found in header name - not valid email
Please contact your IT support personnel with any queries regarding this
policy.
Therefore my question is, how to send an e-mail with attached file properly.
You are misusing the TIdMessageBuilder... classes (TIdMessageBuilderHtml is perfectly capable of creating plain-text emails, but more importantly you are not calling TIdCustomMessageBuilder.FillMessage() to transfer the builder data into the TIdMessage).
You are not populating the TIdMessage correctly (for instance, you are not setting the TIdMessage.ContentType and TIdAttachmentFile.ContentType properties correctly when an attachment is present).
Try something more like this instead:
procedure TMain.SendEmailIndy(
const SMTPServer: string;
const FromName, FromAddress: string;
const ToAddresses: string; //comma separated list of e-mail addresses
const CCAddresses: string; //comma separated list of e-mail addresses
const BCCAddresses: string; //comma separated list of e-mail addresses
const Subject: string;
const EmailBody: string;
const IsBodyHtml: Boolean);
var
smtp: TIdSMTP; // IdSmtp.pas
msg: TidMessage; // IdMessage.pas
builder: TIdMessageBuilderHtml; //IdMessageBuilder.pas
begin
msg := TidMessage.Create(nil);
try
builder := TIdMessageBuilderHtml.Create;
try
if IsBodyHtml then
begin
builder.Html.Text := EmailBody;
builder.HtmlCharSet := 'utf-8';
builder.HtmlContentTransfer := 'quoted-printable';
end else
begin
builder.PlainText.Text := EmailBody;
builder.PlainTextCharSet := 'utf-8';
builder.PlainTextContentTransfer := 'quoted-printable';
end;
if Realization.AttachmentD.FileName <> '' then
begin
builder.Attachments.Add(Realization.AttachmentD.FileName);
ShowMessage('Sending: ' + Realization.AttachmentD.FileName);
end;
builder.FillMessage(msg);
finally
builder.Free;
end;
msg.From.Name := FromName;
msg.From.Address := FromAddress;
msg.Subject := Subject;
msg.Recipients.EmailAddresses := ToAddresses;
msg.CCList.EmailAddresses := CCAddresses;
msg.BccList.EmailAddresses := BCCAddresses;
smtp := TIdSMTP.Create(nil);
try
smtp.Host := SMTPServer; // IP Address of SMTP server
Smtp.UseTLS := utNoTLSSupport;
smtp.Port := 587; //The default already is port 25 (the SMTP port)
smtp.Username := _GlobalData.EMail;
smtp.Password := _GlobalData.Password;
smtp.AuthType := satDefault;
smtp.Connect;
try
smtp.Send(msg);
finally
smtp.Disconnect;
end;
finally
smtp.Free;
end;
finally
msg.Free;
end;
ShowMessage('Wiadomość wysłana.');
Realization.AttachmentD.FileName := '';
end;

Sending emails from the USA

My program uses Indy 10 TIdSMTP and TIdMessage to send error reports via email. The program is used mainly in Germany, but some clients are in the USA.
The tool works flawlessly in Germany, but the USA clients are not able to send anything at all. The output shows that the connection to the German email server (smtp.web.de) is made, but after that, an immediate disconnect follows. The exception "Socket error #10054 connection reset by peer" is thrown.
Here's some code:
procedure SendMail(const PI_sSenderAddress: string; const PI_arrReceiverAddresses, PI_arrCCAddresses, PI_arrBCCAddresses: array of string; const PI_sSubject, PI_sMailText: string; const PI_arrAttachments: array of string; const PI_sHost: string = ''; const PI_sUsername: string = ''; const PI_sPassword: string = ''; const PI_bUseTLS: boolean = False; const PI_nPort: integer = 25; const PI_nTimeoutSeconds: integer = 5 );
var
smtp: TIdSMTP;
Mail: TIdMessage;
i: integer;
arrAttachments: array of TIdAttachmentFile;
io: TIdSSLIOHandlerSocketOpenSSL;
begin
io := nil;
smtp := TIdSMTP.Create(Application);
try
smtp.Password := PI_sPassword;
smtp.Username := PI_sUsername;
smtp.Port := PI_nPort;
smtp.Host := PI_sHost;
if PI_bUseTLS then begin
io := TIdSSLIOHandlerSocketOpenSSL.Create(Application);
smtp.IOHandler := io;
end;
smtp.UseTLS := utUseRequireTLS;
if PI_sUserName <> '' then begin
smtp.AuthType := satDefault;
end else begin
smtp.AuthType := satNone;
end;
smtp.HeloName := Split(PI_sUsername, 1, '#');
mail := TIdMessage.Create( Application );
try
mail.Clear;
mail.From.Address := PI_sSenderAddress;
mail.From.Text := PI_sSenderAddress;
mail.Subject := PI_sSubject;
mail.Recipients.EMailAddresses := ArrayToStr( PI_arrReceiverAddresses, ',' ); //!! only one
mail.CCList.EMailAddresses := ArrayToStr( PI_arrCCAddresses, ',' );
mail.BccList.EMailAddresses := ArrayToStr( PI_arrBCCAddresses, ',' );
mail.ReceiptRecipient.Text := '';
mail.Body.Add( PI_sMailText );
mail.Date := now;
if Length(PI_arrAttachments) > 0 then begin
SetLength(arrAttachments, Length(PI_arrAttachments));
for i := 0 to High(PI_arrAttachments) do begin
arrAttachments[i] := TIdAttachmentFile.Create(mail.MessageParts, PI_arrAttachments[i]);
end;
end;
try
smtp.ConnectTimeout := PI_nTimeoutSeconds * 1000;
smtp.Connect;
if smtp.Connected then begin
smtp.Send(mail);
end;
finally
smtp.disconnect;
if Length(arrAttachments) > 0 then begin
for i := 0 to High(arrAttachments) do begin
arrAttachments[i].Free;
end;
end;
end;
finally
mail.Free;
end;
finally
smtp.free;
if Assigned(io) then io.Free;
end;
end;
I call it like this:
SendMail(
'myaccount#web.de',
['receiver#web.de'],
[],
[],
'Subject',
'Text',
[],
'smtp.web.de',
'myaccount#web.de',
'mypassword',
True,
587
);
Can someone help?
EDIT: I changed to a googlemail account, but getting the same error. Currently, i call it like this:
I call it like this:
SendMail(
'myaccount#gmail.com',
['receiver#web.de'],
[],
[],
'Subject',
'Text',
[],
'smtp.gmail.com',
'myaccount#gmail.com',
'mypassword',
True,
587
);