Recent

Author Topic: Synapse email send three times  (Read 4624 times)

SymbolicFrank

  • Hero Member
  • *****
  • Posts: 1313
Synapse email send three times
« on: November 27, 2015, 11:22:42 am »
I use the complete synalist package that includes ssl_openssl.

The application runs on Windows 7 64.

I send the mail with SendToEx.

If I trace it with the debugger, I see that the parts of the mail are send sequentially (EHLO, LOGIN, user, pass, FROM, TO, DATA, QUIT). Once.

But the mail is received three times.

When I look with wireshark, I see that the complete sequence is repeated three times.

Help?

rvk

  • Hero Member
  • *****
  • Posts: 6163
Re: Synapse email send three times
« Reply #1 on: November 27, 2015, 11:29:54 am »
Some code would be nice. (please put them between [ code ] tags)

With what exactly do you fill MailTo?
SendToEx expands the MailTo, which can be separated by commas, to multiple e-mail addresses.

How many "RCPT TO" do you see?
« Last Edit: November 27, 2015, 11:33:21 am by rvk »

SymbolicFrank

  • Hero Member
  • *****
  • Posts: 1313
Re: Synapse email send three times
« Reply #2 on: November 27, 2015, 02:24:39 pm »
I send it to just a single recepient.

As for code: The plot thickens.

I removed Synapse and installed lNet. I couldn't get it to send an email at all. So, I tried to install Indy 10.2.0.3. It gives a "Header error" when unzipping (I tried two different ones). And it makes Lazarus crash during the rebuild when installing. It also generates dangerous-looking error messages and only half the components end up installed.

So I uninstalled Indy, and just added it to the project. And when sending an email... it sends 3 as well.

Current code:
Code: [Select]
function MailError(Location, Message: string): Boolean;
var
  MySMTP: TIdSMTP;
  MyMessage: TIdMessage;
  MySSL: TIdSSLIOHandlerSocketOpenSSL;
begin
  Result := False;
  MySMTP := TIdSMTP.Create;
  MySSL := TIdSSLIOHandlerSocketOpenSSL.Create;
  MySMTP.IOHandler := MySSL;
  MyMessage := TIdMessage.Create;

  try
    MyMessage.From.Name := Sender;
    MyMessage.From.Address := Sender;
    MyMessage.ReplyTo.EMailAddresses := Sender;
    MyMessage.Recipients.EMailAddresses := Receiver;
    MyMessage.Subject := Location;
    MyMessage.MessageParts.Clear;
    MyMessage.Body.Text := Message;
    MyMessage.Date := SysUtils.Date;

    MySMTP.Host := SMTPHost;
    MySMTP.Port := SMTPPort;
    MySMTP.UserName := UserName;
    MySMTP.PassWord := Password;
    MySMTP.Connect;
    MySMTP.Authenticate;
    MySMTP.Send(MyMessage);
    MySMTP.Disconnect;
    Result := True;

  finally
    MyMessage.Free;
    MySMTP.Free;
    MySSL.Free;
  end;
end;

Sender and receiver are both the same, single email address.

When debugging the first version (Synapse), there was a single RCPT TO. And each action is send separately.

But in Wireshark, the whole message gets repeated a second later, twice.


Edit: If I run it on a slow XP computer, it sends the message only twice.
« Last Edit: November 27, 2015, 02:42:20 pm by SymbolicFrank »

rvk

  • Hero Member
  • *****
  • Posts: 6163
Re: Synapse email send three times
« Reply #3 on: November 27, 2015, 02:29:48 pm »
So I uninstalled Indy, and just added it to the project. And when sending an email... it sends 3 as well.
...
But in Wireshark, the whole message gets repeated a second later, twice.
Your problem is not in your code or Synapse/Indy but in your mailserver (if it's a local one).

You say the mail gets send 3 times. What kind of SMTP-server are you using? A local one? Or are you directly sending to smtp.yourprovider.com?

Are you sure your function MailError() is only called once (you could put in a showmessage to make sure)??
« Last Edit: November 27, 2015, 02:32:23 pm by rvk »

SymbolicFrank

  • Hero Member
  • *****
  • Posts: 1313
Re: Synapse email send three times
« Reply #4 on: November 27, 2015, 02:45:44 pm »
I tried two local mailservers, the first is Windows SBS2003 with IIS6, the other is Debian 7, I don't know what mailserver.

But I see the messages being repeated in Wireshark.


Edit: Yes, when I set a breakpoint on the MailError function and trace through the whole process, it sends it only once. And the breakpoint is triggered only once as well.
« Last Edit: November 27, 2015, 02:47:39 pm by SymbolicFrank »

rvk

  • Hero Member
  • *****
  • Posts: 6163
Re: Synapse email send three times
« Reply #5 on: November 27, 2015, 02:49:23 pm »
I tried two local mailservers, the first is Windows SBS2003 with IIS6, the other is Debian 7, I don't know what mailserver.
But I see the messages being repeated in Wireshark.
Yeah, I meant local to your computer. Because you run WireShark on your computer, something needs to be really sending the mail 3 times. Your SBS2003 and Debian are in your network but not on your computer. So the only thing I can think of is that your function MailError() gets called 3 times. If you put a showmessage at the end of the function and don't click ok but let it sit there you can see if the mail gets send only once.

B.T.W. doesn't wireshark show which process send the real data? Is that your application?

SymbolicFrank

  • Hero Member
  • *****
  • Posts: 1313
Re: Synapse email send three times
« Reply #6 on: November 27, 2015, 02:58:26 pm »
Your suggestion of using a ShowMessage was a good one! While the breakpoint is only triggered once, it shows three messages.

I removed the call from the FormCreate (which is only called once, as far as breakpoints go) and made a button. Pressing the button sends a single email...

Why it was called multiple times without triggering breakpoints, I don't know. But it seems to work now...


Edit: I restored the Synapse SendToEx, and it works as well.

After further investigation, I think I know what is happening:

There is a TChromium component on the form, and if I look in the TaskManager, it shows three processes. Only one of them (the main/GUI thread) is visible, but it seems that the other two have a form as well, and that the constructor executes.

I was under the impression that those other processes contained only the CEF3 processes, but it seems they're forks.
« Last Edit: November 27, 2015, 03:31:34 pm by SymbolicFrank »

rvk

  • Hero Member
  • *****
  • Posts: 6163
Re: Synapse email send three times
« Reply #7 on: November 27, 2015, 03:34:32 pm »
There is a TChromium component on the form, and if I look in the TaskManager, it shows three processes. Only one of them (the main/GUI thread) is visible, but it seems that the other two have a form as well, and that the constructor executes.
So because of the TChromium the complete process (including form) gets forked 2 times and the FormCreate is executed three times  %)
(Good to know  :D)

 

TinyPortal © 2005-2018