Skip to content

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

@Andrewsville

Description

@Andrewsville
  • 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions