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

ENH: Displaying status_code of the email status would be good for better error handling #57

Open
Yawan-1 opened this issue Sep 30, 2022 · 2 comments
Labels
enhancement New feature or request

Comments

@Yawan-1
Copy link

Yawan-1 commented Sep 30, 2022

I tried to find this feature but I didn't find it. so I am trying to get status_code of the email's status like "If the email was successfully sent or failed" and "If failed then How email failed", I mean what reason effected the email failure. If the console is showing error like -

smtplib.SMTPRecipientsRefused: {'user': (553, b'5.1.3 The recipient address is not a valid RFC-5321 address. Learn\n5.1.3 more at\n5.1.3 https://support.google.com/mail/answer/6596 ik12-20020a170902ab0cm2094481plb.177 - gsmtp')}

or

socket.gaierror: [Errno 11001] getaddrinfo failed

so, A developer will want to show or pass the appropriate message to the user in frontend on "What went wrong" or "What causes the email failure" ? but in this case It will only be seen as "something went wrong" (No status code or a clean message) to pass forward.

For Example -

email = EmailSender(
    host="smtp.gmail.com", port=587,
    username="xyz123", password="xyz123"
)

email.send(
    sender="[email protected],
   receivers=["[email protected]"],
   subject="An example email",
)

and If I try to print the EmailSender class calling variable print(email). Then it prints Class object Binary.

so It would be better to show more information about email just sent.

@Yawan-1 Yawan-1 added the enhancement New feature or request label Sep 30, 2022
@Miksus
Copy link
Owner

Miksus commented Oct 2, 2022

Red Mail should not do any silencing on the error: whatever the smtplib raises will be passed through Red Mail to the user of the library. And the user can process the exception however needed.

Do you mean you would like to have better errors than what smtplib produces? Perhaps a valid point but it should be done with extreme care so that no information is lost. Error silencing for the sake of a status code is something I'm very against.

Furthermore, your example produces quite an intuitive exception though (you are missing a quote):

smtplib.SMTPAuthenticationError: (535, b'5.7.8 Username and Password not accepted. Learn more at\n5.7.8  https://support.google.com/mail/?p=BadCredentials q3-20020a0565123a8300b00498fc3d4d15sm1004920lfu.190 - gsmtp')

@Yawan-1
Copy link
Author

Yawan-1 commented Oct 5, 2022

It's not just about 'status_code', it can be done by passing status_code with appropriate message.

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

No branches or pull requests

2 participants