Recent

Author Topic: XMAILER works fine until I want the user to be able to change settings  (Read 3335 times)

ACDigital

  • Newbie
  • Posts: 6
This works

Code: Pascal  [Select][+][-]
  1. Mailer.smtp.username:='hello@hello.hel';
  2. Mailer.smtp.password:='fpclove123';
  3. Mailer.smtp.host:='mysmtp.hello.hel';
  4. Mailer.smtp.port:='587';

This does not work

Code: Pascal  [Select][+][-]
  1. Mailer.smtp.username:=unameedit.text;
  2. Mailer.smtp.password:=passedit.text;
  3. Mailer.smtp.host:=hostedit.text;
  4. Mailer.smtp.port:=portedit.text;

It results in an error SMTP::Mail to ???

What am I doing wrong? Im not at home right now so this was written on my phone, but the problem appears when I'm trying to use the host, port, username and password from a tedit instead of actual 'strings'. I don't get any other information about the error so I would really appreciate if someone could point me in the right direction.

This happens on both macos and windows.

EDIT:
Attached a sample project. Edit Button1-Click and it will work, use the edits and it wont.

« Last Edit: June 09, 2019, 09:38:11 am by ACDigital »

wp

  • Hero Member
  • *****
  • Posts: 12787
No problem for me (I am on Windows).

wp

  • Hero Member
  • *****
  • Posts: 12787
Both cases work for me after I remove the "mailer.SMTP.FullSSL := false".

Please do not post source code on external url, it will be gone after some time, and when somebody is reading this thread then it will not be available any more. In order to post code here, pack all your SOURCE files (i.e. .pas, .lfm, .lpi and .lpr) plus data files needed into a common zip which you can upload under "Attachment and ohter options". Do not add compiler generated files, such as .exe, .ppu, .o, .compiled etc - they are not needed and may increase the total file size above the max upload limit of 250 kB.

ACDigital

  • Newbie
  • Posts: 6
Both cases work for me after I remove the "mailer.SMTP.FullSSL := false".

Please do not post source code on external url, it will be gone after some time, and when somebody is reading this thread then it will not be available any more. In order to post code here, pack all your SOURCE files (i.e. .pas, .lfm, .lpi and .lpr) plus data files needed into a common zip which you can upload under "Attachment and ohter options". Do not add compiler generated files, such as .exe, .ppu, .o, .compiled etc - they are not needed and may increase the total file size above the max upload limit of 250 kB.

Thank you for pointing that out, the project is now an attachment.

Well this is really wierd to me. I need to disable full SSL in order to login correctly. I can not understand how both options works for you but not for me. I have tried on two Windows 10 machines and one Macbook. First I was thinking it was my email provider, but that doesnt explain how it works when i "hardcode" the strings?

I tried it again this morning, see attached error message.

Anyway, thank you for your response.

ACDigital

  • Newbie
  • Posts: 6
Well I'm confused. Now it works, took the exact same code and pasted it into another project and now it works. What could have been the problem? Am I going crazy maybe?  :-\

Soner

  • Sr. Member
  • ****
  • Posts: 319
I did not try your example but I am using XMailer with this properties:
  Mailer.Smtp.SSL := false;
  Mailer.Smtp.TLS := True;   
I can send to all email provider like google, hotmail, gmx and others without problems. Also I can change user name, password, port, server adresses on the fly.

I did not touch the property mailer.SMTP.FullSSL, it has default value. And I am using libeay32.dll and ssleay32.dll from Indy-Project.
I put the dll's in application folder.

wp

  • Hero Member
  • *****
  • Posts: 12787
Well I'm confused. Now it works, took the exact same code and pasted it into another project and now it works. What could have been the problem? Am I going crazy maybe?  :-\
I guess: typo in the password, confuse lowercase-L with "1", confuse uppercase O with zero etc.

But I agree: sending of email with SSL/TLS etc is still a mystery to me. I have two providers, according to Thunderbird they have the same port and SSL and TLS settings, but XMailer can send only by one of them.

Thaddy

  • Hero Member
  • *****
  • Posts: 16932
  • Ceterum censeo Trump esse delendam
There's more wrong. Suggest to change to this:
Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button2Click(Sender: TObject);
  2. var
  3.   mailer: TSendMail;
  4. begin
  5.     try
  6.        mailer := TSendMail.Create;
  7.       try
  8.          mailer.Sender := 'myname <myname@lolsor.com>';
  9.          mailer.Receivers.Add('tosome@lol.com');
  10.          mailer.Subject := 'TEST';
  11.          mailer.Message.Add('Test');
  12.          mailer.Smtp.UserName := username.text;
  13.          mailer.Smtp.Password := password.text;
  14.          mailer.Smtp.Host := host.Text;
  15.          mailer.Smtp.Port := port.text;
  16.          mailer.Smtp.SSL := false; // this is either / or with TLS
  17.          mailer.Smtp.TLS := True; // this is either / or with - deprecated!!!! SSL
  18.          mailer.Smtp.FullSSL:=false;
  19.          mailer.Send;
  20.      except
  21.         on E:Exception do
  22.         ShowMessage('error');
  23.       end;
  24.   finally
  25.     mailer.Free;
  26.   end;
  27. end;  
         

The way you wrote your code causes a leak and side effects when an exception is raised, because the mailer object is not free'd in such a case. Hence the try /finally....
I also commented the code WHY SSL/and TLS should be mutual exclusive (wp's suggestion was correct!, but FullSSL can be true when SSL is excluded, I believe))
« Last Edit: June 09, 2019, 04:26:00 pm by Thaddy »
Due to censorship, I changed this to "Nelly the Elephant". Keeps the message clear.

ACDigital

  • Newbie
  • Posts: 6
There's more wrong. Suggest to change to this:
Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button2Click(Sender: TObject);
  2. var
  3.   mailer: TSendMail;
  4. begin
  5.     try
  6.        mailer := TSendMail.Create;
  7.       try
  8.          mailer.Sender := 'myname <myname@lolsor.com>';
  9.          mailer.Receivers.Add('tosome@lol.com');
  10.          mailer.Subject := 'TEST';
  11.          mailer.Message.Add('Test');
  12.          mailer.Smtp.UserName := username.text;
  13.          mailer.Smtp.Password := password.text;
  14.          mailer.Smtp.Host := host.Text;
  15.          mailer.Smtp.Port := port.text;
  16.          mailer.Smtp.SSL := false; // this is either / or with TLS
  17.          mailer.Smtp.TLS := True; // this is either / or with - deprecated!!!! SSL
  18.          mailer.Smtp.FullSSL:=false;
  19.          mailer.Send;
  20.      except
  21.         on E:Exception do
  22.         ShowMessage('error');
  23.       end;
  24.   finally
  25.     mailer.Free;
  26.   end;
  27. end;  
         

The way you wrote your code causes a leak and side effects when an exception is raised, because the mailer object is not free'd in such a case. Hence the try /finally....
I also commented the code WHY SSL/and TLS should be mutual exclusive (wp's suggestion was correct!, but FullSSL can be true when SSL is excluded, I believe))

You are absolutely right. This is fixed in my actual application. Thanks for pointing that out.

 

TinyPortal © 2005-2018