Recent

Author Topic: [SOLVED] Faster Email  (Read 16798 times)

rvk

  • Hero Member
  • *****
  • Posts: 6716
Re: Faster Email
« Reply #15 on: June 10, 2017, 02:31:46 pm »
@rvk:
... And say hello to the next ransomware ...
If course I meant temporarily. And if it turns out to be your AV, you should replace it with a better one.

RAW

  • Hero Member
  • *****
  • Posts: 868
Re: Faster Email
« Reply #16 on: June 10, 2017, 02:35:21 pm »
Quote
... And say hello to the next ransomware ...
A good firewall can handle every ransomware without any problems and without scanning for signatures, but not every person can handle a good firewall...  :P  :D
Windows 7 Pro (x64 Sp1) & Windows XP Pro (x86 Sp3).

ramutau

  • New Member
  • *
  • Posts: 40
Re: Faster Email
« Reply #17 on: June 10, 2017, 02:50:09 pm »
Yep , I pretty much can't disable the Firewal and AV on my client's PCs...

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: Faster Email
« Reply #18 on: June 10, 2017, 04:31:01 pm »
Thanks for all the responses. Appreciated.

This is the piece of my code:

         Mail.Smtp.UserName := Gmail_Address_VAR;
         Mail.Smtp.Password := Gmail_Password_VAR;
         Mail.Smtp.Host := 'smtp.gmail.com';
         Mail.Smtp.Port := '465';
         Mail.Smtp.SSL := True;
         Mail.Smtp.TLS := True;
         Mail.Send; 

It takes 5 to 7 seconds just on the Mail.Send statement.

I have excluded the app from the Firewall and AV.

I don't know anything about asynchronous multithreading, but I'm going to learn.

Noob question: Am I just going to run the one statement "Mail.Send" in another thread?
I have to remind you of the rule in my last post, do not use any variables/objects outside of the thread. Create a new mail object inside the thread and use its properties and send method. Do not rely on external data at all. The hard part of multithreading is synchronizing access to shared data so make sure you do not share any data for starters.

Quote
... And say hello to the next ransomware ...
A good firewall can handle every ransomware without any problems and without scanning for signatures, but not every person can handle a good firewall...  :P :D
Experienced, well gifted user seeks acquaintance with hot and wide firewall for immediate marriage. :P
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

RAW

  • Hero Member
  • *****
  • Posts: 868
Re: Faster Email
« Reply #19 on: June 10, 2017, 05:09:22 pm »
Quote
Experienced, well gifted user seeks acquaintance with hot and wide firewall for immediate marriage. :P
:D :D :D

Immediate marriage... ?? That's risky, maybe she's a pig in a poke :)
Is it nowadays quite right to get married to somebody or is that an ancient behaviour that should be handled carefully... ?? Don't trust the white rabbit... :P
Windows 7 Pro (x64 Sp1) & Windows XP Pro (x86 Sp3).

ramutau

  • New Member
  • *
  • Posts: 40
Re: Faster Email
« Reply #20 on: June 10, 2017, 05:25:13 pm »
@rvk:
... And say hello to the next ransomware ...
If course I meant temporarily. And if it turns out to be your AV, you should replace it with a better one.

Thanks rvk, I understood it like that. Made very little difference.

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: Faster Email
« Reply #21 on: June 10, 2017, 05:48:35 pm »
Quote
Experienced, well gifted user seeks acquaintance with hot and wide firewall for immediate marriage. :P
:D :D :D

Immediate marriage... ?? That's risky, maybe she's a pig in a poke :)
its a firewall the ugliest the better. We want to keep people out not welcome them in. :P
Is it nowadays quite right to get married to somebody or is that an ancient behaviour that should be handled carefully... ?? Don't trust the white rabbit... :P
I have no idea. But divorce is part of marriage, divorcing a firewall is way way way chipper so I have nothing to loose except of course the cost of marriage so my intentions are honorable but if it asks to much.... ;)
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

ramutau

  • New Member
  • *
  • Posts: 40
Re: Faster Email
« Reply #22 on: June 10, 2017, 06:35:12 pm »
Please accept my apologies in advance for this noobie question.

I am going to learn all about multi-threading etc., but as taazz said, it is a steep learning curve, and I need a solution really pronto.

My question is, will it really solve my problem, after all?

I have one problem only here, the fact that the "Mail.Send;" statement takes 5 seconds.

What sows doubt in my mind is that some of the other comments seem to say that there should be no reason for it to take 5 seconds, even without multithreading.





RAW

  • Hero Member
  • *****
  • Posts: 868
Re: Faster Email
« Reply #23 on: June 10, 2017, 06:36:42 pm »
Quote
its a firewall the ugliest the better. We want to keep people out not welcome them in. :P
Yeah, true...

Quote
..But divorce is part of marriage...
Don't tell that any wife ...  :)

Quote
..divorcing a firewall is way way way chipper...
And more secure... take a look at Robin Williams ...   :o >:(


I don't know much about Linux, but I would say one should have at least AppAmor running or better GRSecurity or something like that. Of course it depends on what you do with the computer.
On Windows: I like JETICO INC., but yes there's plenty of crapware/shlockware/wasteware (whatever you may call it..) available... GOOD LUCK !  :D

In the end I had to trust software because I can't program everything myself and of course I can't do it because of the lack of time and knowledge.
Windows 7 Pro (x64 Sp1) & Windows XP Pro (x86 Sp3).

bylaardt

  • Sr. Member
  • ****
  • Posts: 310
Re: Faster Email
« Reply #24 on: June 10, 2017, 07:10:29 pm »
What sows doubt in my mind is that some of the other comments seem to say that there should be no reason for it to take 5 seconds, even without multithreading.
5 seconds is probably AV analysis time. IMO Everything you do is just placebo for the real problem.
Your code is fine.

rvk

  • Hero Member
  • *****
  • Posts: 6716
Re: Faster Email
« Reply #25 on: June 10, 2017, 07:30:40 pm »
My question is, will it really solve my problem, after all?
It will solve your problem, but not the root of your problem.

Quote
I have one problem only here, the fact that the "Mail.Send;" statement takes 5 seconds.
What kind of code is that? Not Synapse.

I do see that smtp.gmail.com is really really really really slow.
I now see why you have that delay.

Did you try another smtp-provider yet?

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: Faster Email
« Reply #26 on: June 10, 2017, 07:35:49 pm »
Please accept my apologies in advance for this noobie question.

I am going to learn all about multi-threading etc., but as taazz said, it is a steep learning curve, and I need a solution really pronto.

My question is, will it really solve my problem, after all?

I have one problem only here, the fact that the "Mail.Send;" statement takes 5 seconds.

What sows doubt in my mind is that some of the other comments seem to say that there should be no reason for it to take 5 seconds, even without multithreading.
I have no idea what your problem is no one has. In order for us to actually solve your problem you need to either identify it for us or help us recreate it in a laboratory for testing. What I propose is do not try to solve the problem just hide it under the rag by using a secondary process to send the emails and as a result your main application does not freeze for 5 seconds waiting for the email to be send.

That is the way all email clients work, take a look on mozila thunderbird for example, it does not block you from working but the "mail window" remains open for a few seconds after you press the send button. Why don't you install thunderbird and send an email with it for testing see how long it takes thunderbird to send it and compare that with your application.

Overall are you sure that your problem is that it takes 5 seconds to send an email and not that your program freezes for 5 seconds while sending the email?
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: Faster Email
« Reply #27 on: June 10, 2017, 07:37:36 pm »
My question is, will it really solve my problem, after all?
It will solve your problem, but not the root of your problem.

Quote
I have one problem only here, the fact that the "Mail.Send;" statement takes 5 seconds.
What kind of code is that? Not Synapse.

I do see that smtp.gmail.com is really really really really slow.
I now see why you have that delay.

Did you try another smtp-provider yet?
or use imap with google instead?
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

rvk

  • Hero Member
  • *****
  • Posts: 6716
Re: Faster Email
« Reply #28 on: June 10, 2017, 07:47:28 pm »
Ok, with this snippet I got it to 1,5 seconds with Synapse.

Code: Pascal  [Select][+][-]
  1. uses smtpsend, ssl_openssl;
  2.  
  3. const
  4.   Username = 'xxx@gmail.com';
  5.   Password = 'xxx';
  6.  
  7. procedure TForm1.btSendNormalClick(Sender: TObject);
  8. var
  9.   Message: TStringList;
  10. begin
  11.   Message := TStringList.Create;
  12.   try
  13.     Message.Add('This is a test');
  14.     if SendToEx(Username, Username, 'Test', 'smtp.gmail.com:465', Message, Username, Password) then
  15.       Showmessage('Sending mail successful.')
  16.     else
  17.       Showmessage('Error sending mail.');
  18.   finally
  19.     Message.Free;
  20.   end;
  21. end;

and don't forget to set SMTP.FullSSL in smtpsend.pas in Synapse to true:
Code: Pascal  [Select][+][-]
  1.     //SMTP.AutoTLS := True;
  2.     SMTP.FullSSL := True;

So it still might be something in your code.

rvk

  • Hero Member
  • *****
  • Posts: 6716
Re: Faster Email
« Reply #29 on: June 10, 2017, 07:50:54 pm »
O, and with a thread you could do something like this:
(But I would find out why it takes 5-7 seconds for you first because as you can see above, for me it took 1,5 seconds)

Code: Pascal  [Select][+][-]
  1. uses smtpsend, ssl_openssl;
  2.  
  3. const
  4.   Username = 'xxx@gmail.com';
  5.   Password = 'xxx';
  6.  
  7. type
  8.   TMyMailThread = class(TThread)
  9.   protected
  10.     procedure Execute; override;
  11.   public
  12.     FMessage: TStringList;
  13.     FMailFrom, FMailTo, FSubject: String;
  14.     constructor Create(const MailFrom, MailTo, Subject: String; const Message: TStringList);
  15.     destructor Destroy; override;
  16.     procedure ShowSuccess;
  17.     procedure ShowError;
  18.   end;
  19.  
  20. constructor TMyMailThread.Create(const MailFrom, MailTo, Subject: String; const Message: TStringList);
  21. begin
  22.   FreeOnTerminate := True;
  23.   FMessage := TStringList.Create;
  24.   FMessage.Assign(Message);
  25.   FMailFrom := MailFrom;
  26.   FMailTo := MailTo;
  27.   FSubject := Subject;
  28.   inherited Create(false);
  29. end;
  30.  
  31. destructor TMyMailThread.Destroy;
  32. begin
  33.   inherited;
  34.   FMessage.Free;
  35. end;
  36.  
  37. procedure TMyMailThread.ShowSuccess;
  38. begin
  39.   Showmessage('Success'); // you can access Form1 from here
  40. end;
  41.  
  42. procedure TMyMailThread.ShowError;
  43. begin
  44.   Showmessage('Error'); // you can access Form1 from here
  45. end;
  46.  
  47. procedure TMyMailThread.Execute;
  48. begin
  49.   if SendToEx(FMailFrom, FMailTo, FSubject, 'smtp.gmail.com:465', FMessage, Username, Password) then
  50.     Synchronize(@ShowSuccess)
  51.   else
  52.     Synchronize(@ShowError);
  53. end;
  54.  
  55. procedure TForm1.btSendInThreadClick(Sender: TObject);
  56. var
  57.   Message: TStringList;
  58.   MyMailThread: TMyMailThread;
  59. begin
  60.   Message := TStringList.Create;
  61.   try
  62.     Message.Add('This is a test');
  63.     MyMailThread := TMyMailThread.Create(Username, Username, 'Testmail', Message);
  64.   finally
  65.     Message.Free;
  66.   end;
  67. end;
« Last Edit: June 10, 2017, 07:52:45 pm by rvk »

 

TinyPortal © 2005-2018