Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SmtpMailer leaves a connection mid-communication when not able to build a message #42

Closed
Andrewsville opened this issue Jul 22, 2017 · 1 comment

Comments

@Andrewsville
Copy link
Contributor

Andrewsville commented Jul 22, 2017

  • bug report? yes
  • feature request? no
  • version: trunk

Description

Before the Message::generateMessage() method gets called, there is already some communication with the SMTP server. If the method for some reason throws an exception other than Nette\Mail\SmtpException, sending the message aborts but the connection is kept open. If you send another message using the same sender, the SMTP server will probably return something like 503 sender already given because from its point of view you are still sending the first faulty message.

How can this happen: Using vanilla Nette\Mail\Message it probably can't. However because of how the Message builds itself when being sent and because the $parts property is private, it is impossible to build a wrapper/proxy/decorator/something that would encapsulate an existing message and encrypt/sign it for example. The only feasible way I've found is a to subclass the Message class and handle the signature/encryption part inside the build() method. And this can obviously fail. And if it throws something else than Nette\Mail\SmtpException GO TO previous paragraph.

The fix is simple - only change the order of things inside SmtpSender::send(). PR #43 present.

Steps To Reproduce

Throw an exception (any other than Nette\Mail\SmtpException) from Message::build() or Message::generateMessage() and try sending another message (with or without such exception) on the same sender.

@Andrewsville
Copy link
Contributor Author

Fixed by #43

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant