Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to continue execution after traceback error

sometime i got

Traceback '(most recent call last):
  File "main.py", line 45, in <module>
    server.sendmail(sender, receiver, msg.as_string())
  File "/nix/store/2vm88xw7513h9pyjyafw32cps51b0ia1-python3-3.8.12/lib/python3.8/smtplib.py", line 899, in sendmail
    raise SMTPRecipientsRefused(senderrs)
smtplib.SMTPRecipientsRefused: {'example@gmail.com': (550, b'The mail server could not deliver mail to example@gmail.com.  The account\nor domain may not exist, they may be blacklisted, or missing the proper dns\nentries.')}'

and script get stopped
i need to know if there solution to continue after any error

with smtplib.SMTP(smtpsv, port) as server:

server.starttls() # Secure the connection

server.login(user, password)
server.sendmail(sender, receiver, msg.as_string())
print(" + {}: {} sent succeffully".format(count, line.strip()))

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You can implement try/except to handle error without breaking the flow,

import traceback
try:
    with smtplib.SMTP(smtpsv, port) as server:
        server.starttls() # Secure the connection

        server.login(user, password)
        server.sendmail(sender, receiver, msg.as_string())
        print(" + {}: {} sent succeffully".format(count, line.strip()))
except Exception:
    print(traceback.print_exc())
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading