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

SMTP.quit() called when not connected #93

Closed
tlynn opened this issue Nov 12, 2014 · 6 comments
Closed

SMTP.quit() called when not connected #93

tlynn opened this issue Nov 12, 2014 · 6 comments

Comments

@tlynn
Copy link

tlynn commented Nov 12, 2014

Connection.exit() tries to call quit() even if there's no socket connection. "if self.host" should say "if self.host and getattr(self.host, 'sock', None)" to match the check in smtplib.SMTP.quit().

@tlynn
Copy link
Author

tlynn commented Nov 12, 2014

I think the problem manifests when the mail server drops the connection and smtplib detects this during a send or reply-reading. On detecting the problem, smtplib closes the connection and raises an exception (in send or getreply) and the Connection.exit() handler then tries to write a "quit" to the connection, which causes a new exception that masks the underlying error.

@Garito
Copy link

Garito commented Feb 16, 2015

Hi!
I posted this issue: #98 that perhaps has to do with this error because the exim people said to me that the error was caused by the app (flask-mail?)

Seems that the app closes the connection before end the sending so SMTPServerDisconnected: please run connect() first is raised

I have some exim logs to ilustrate this problem @ http://pastebin.com/EPCcfj6e

Hope this will help because I still have random errors

Thanks!

@tlynn
Copy link
Author

tlynn commented Feb 17, 2015

This issue should really be sorted by now, I included the required fix in the first comment (and justified it in the second).

@Garito
Copy link

Garito commented Feb 18, 2015

But is this pushed already?
Need to fix the error

@Garito
Copy link

Garito commented Feb 23, 2015

So, can you push the correction to pypi?
My app don't stop raising errors because of that
And my users are starting to be nervous, they ask me to change this library or do something about

tlynn added a commit to tlynn/flask-mail that referenced this issue Mar 14, 2015
tlynn added a commit to tlynn/flask-mail that referenced this issue Mar 14, 2015
drdaeman added a commit to drdaeman/flask-mail that referenced this issue Oct 23, 2016
There was another commit that silenes disconnection exceptions
during quitting, but this one has a nice test case...
@davidism davidism added this to the 0.10.0 milestone May 23, 2024
@davidism
Copy link
Member

I'm not clear how this issue can happen. We don't call exit(), and SMTP.quit() does not have the check you indicate it does. The following code does not seem to have any issue. If you still have an issue, please open a new issue with a minimal reproducible example and clear description.

from flask import Flask
from flask_mail import Mail, Message

app = Flask(__name__)
app.config.update({
    "MAIL_HOST": "127.0.0.1",
    "MAIL_PORT": 1025,
})
mail = Mail(app)

with app.app_context():
    with mail.connect() as c:
        c.send(Message("test", sender="test", recipients=["test"]))

@davidism davidism closed this as not planned Won't fix, can't repro, duplicate, stale May 23, 2024
@davidism davidism removed this from the 0.10.0 milestone May 23, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 7, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

No branches or pull requests

4 participants