thru sent libreria library from example python python-2.7 smtp smtplib error-code

sent - Manejo de código de error Python SMTP



smtplib python 3 example (1)

He buscado un poco sobre esto y no he podido encontrar nada satisfactorio.

He intentado escribir un programa de Python para escuchar los informes de rebote del correo electrónico y, dependiendo del motivo del rebote, volver a enviarlos a diferentes intervalos.

import smtplib from smtplib import * sender = ''[email protected]'' receivers = [''[email protected]''] message = """From: From Arthur <[email protected]> To: To Deep Thought <[email protected]> Subject: SMTP e-mail test This is a test e-mail message. """ try: smtpObj = smtplib.SMTP(''smtp.gmail.com'',587) smtpObj.starttls() smtpObj.login(sender,''[email protected]'') smtpObj.sendmail(sender, receivers, message) print "Successfully sent email" except SMTPResponseException: error_code = SMTPResponseException.smtp_code error_message = SMTPResponseException.smtp_error print "Error code:"+error_code print "Message:"+error_message if (error_code==422): print "Recipient Mailbox Full" elif(error_code==431): print "Server out of space" elif(error_code==447): print "Timeout. Try reducing number of recipients" elif(error_code==510 or error_code==511): print "One of the addresses in your TO, CC or BBC line doesn''t exist. Check again your recipients'' accounts and correct any possible misspelling." elif(error_code==512): print "Check again all your recipients'' addresses: there will likely be an error in a domain name (like [email protected] instead of [email protected])" elif(error_code==541 or error_code==554): print "Your message has been detected and labeled as spam. You must ask the recipient to whitelist you" elif(error_code==550): print "Though it can be returned also by the recipient''s firewall (or when the incoming server is down), the great majority of errors 550 simply tell that the recipient email address doesn''t exist. You should contact the recipient otherwise and get the right address." elif(error_code==553): print "Check all the addresses in the TO, CC and BCC field. There should be an error or a misspelling somewhere." else: print error_code+": "+error_message

A lo que me sale el siguiente error:

Rastreo (última llamada más reciente): Archivo "C: / Usuarios / Varun Shijo / PycharmProjects / EmailBounce / EmailBounceTest.py", línea 20, en error_code = SMTPResponseException.smtp_code AttributeError: tipo objeto ''SMTPResponseException'' no tiene atributo ''smtp_code''

Leí en alguna parte que debería intentar obtener el atributo de una instancia de la clase SMTPResponseException (aunque la documentación de smtplib dice otheriwse), así que lo intenté también, pero no estaba seguro de qué argumentos para pasar su constructor (código, msg).

¿Podría alguien por favor empujarme en la dirección correcta?

Gracias.


prueba con

except SMTPResponseException as e: error_code = e.smtp_code error_message = e.smtp_error