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

CancelledError thrown when trying to send without authentication #169

Closed
wombatonfire opened this issue Mar 31, 2021 · 2 comments
Closed

Comments

@wombatonfire
Copy link
Contributor

If we try to send_message(msg) through the server, which requires login(), without logging in, a CancelledError will be thrown:

smtp_client = aiosmtplib.SMTP('smtp.office365.com', 587)
await smtp_client.connect()
await smtp_client.starttls()
# await smtp_client.login(username, password)
await smtp_client.send_message(msg)

Traceback:

  File "C:/Users/user/projects/sandbox/mailertest.py", line 514, in run
    await smtp_client.send_message(msg)
  File "C:\Anaconda\envs\sandbox\lib\site-packages\aiosmtplib\smtp.py", line 299, in send_message
    timeout=timeout,
  File "C:\Anaconda\envs\sandbox\lib\site-packages\aiosmtplib\smtp.py", line 174, in sendmail
    await self.rset(timeout=timeout)
  File "C:\Anaconda\envs\sandbox\lib\site-packages\aiosmtplib\esmtp.py", line 128, in rset
    response = await self.execute_command(b"RSET", timeout=timeout)
  File "C:\Anaconda\envs\sandbox\lib\site-packages\aiosmtplib\connection.py", line 420, in execute_command
    response = await self.protocol.execute_command(*args, timeout=timeout)
  File "C:\Anaconda\envs\sandbox\lib\site-packages\aiosmtplib\protocol.py", line 291, in execute_command
    response = await self.read_response(timeout=timeout)
  File "C:\Anaconda\envs\sandbox\lib\site-packages\aiosmtplib\protocol.py", line 259, in read_response
    self._response_waiter, timeout
  File "C:\Anaconda\envs\sandbox\lib\asyncio\tasks.py", line 442, in wait_for
    return fut.result()

While, obviously, you should not forget to authenticate to the server, if it requires you to, throwing CancelledError doesn't seem to me as the correct behavior. I would expect to get some sort of SMTPException instead. In fact, while testing, I got SMTPSenderRefused on multiple occasions, but most of the time CancelledError is raised.

@cole
Copy link
Owner

cole commented Apr 2, 2021

Agree, that's confusing. The connection is being lost, but CancelledError isn't helpful there. Please try the current main branch (if you can) and see if the issue persists for you; it should now raise SMTPSenderRefused, since that's the point where the server raised an error.

@cole
Copy link
Owner

cole commented Apr 25, 2021

1.1.5 is out now, should no longer raise CancelledError.

@cole cole closed this as completed Apr 25, 2021
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

2 participants