You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have been trying to send a user activation mail with flask-mailman and come across this error. I don't quite understand why it happens. have I misconfigured something?
the function that causes this error
@celery.taskdefsend_email(username, email, url):
app=create_app()
withapp.app_context():
withmail.get_connection(backend="smtp") asconnection:
msg=EmailMessage(
"Activate Your account",
f"{username} please confirm your email by going to {url}",
app.config["MAIL_USER"],
[email],
connection=connection,
)
msg.send(fail_silently=False)
2021-04-11 18:05:21,818: ERROR/ForkPoolWorker-4] Task argboard.routes.auth.auth.send_email[8c6ab451-ba1a-4780-80aa-76916670c8ec] raised unexpected: SMTPServerDisconnected('please run connect() first')
Traceback (most recent call last):
File "/home/nullrequest/.local/share/virtualenvs/argboard-Q0PubHYB/lib/python3.9/site-packages/celery/app/trace.py", line 405, in trace_task
R = retval = fun(*args, **kwargs)
File "/home/nullrequest/.local/share/virtualenvs/argboard-Q0PubHYB/lib/python3.9/site-packages/celery/app/trace.py", line 697, in __protected_call__
return self.run(*args, **kwargs)
File "/home/nullrequest/argboard/argboard/routes/auth/auth.py", line 28, in send_email
with mail.get_connection(backend="smtp") as connection:
File "/home/nullrequest/.local/share/virtualenvs/argboard-Q0PubHYB/lib/python3.9/site-packages/flask_mailman/backends/base.py", line 50, in __enter__
self.open()
File "/home/nullrequest/.local/share/virtualenvs/argboard-Q0PubHYB/lib/python3.9/site-packages/flask_mailman/backends/smtp.py", line 67, in open
self.connection.starttls(keyfile=self.ssl_keyfile, certfile=self.ssl_certfile)
File "/usr/lib/python3.9/smtplib.py", line 753, in starttls
self.ehlo_or_helo_if_needed()
File "/usr/lib/python3.9/smtplib.py", line 604, in ehlo_or_helo_if_needed
if not (200 <= self.ehlo()[0] <= 299):
File "/usr/lib/python3.9/smtplib.py", line 444, in ehlo
self.putcmd(self.ehlo_msg, name or self.local_hostname)
File "/usr/lib/python3.9/smtplib.py", line 371, in putcmd
self.send(str)
File "/usr/lib/python3.9/smtplib.py", line 363, in send
raise SMTPServerDisconnected('please run connect() first')
smtplib.SMTPServerDisconnected: please run connect() first
The text was updated successfully, but these errors were encountered:
FWIW - I can run with Celery with no problems. One possible thing I see is that you are doing the create_app() inside the celery task - not sure why you would do that - presumably, you are using Flask and should have already created the 'app' and use that SAME global app to set up a context.
I have been trying to send a user activation mail with flask-mailman and come across this error. I don't quite understand why it happens. have I misconfigured something?
the function that causes this error
The text was updated successfully, but these errors were encountered: