I have this code and I cannot seem to get it to work. When I run it, the script doesn't finish in IDLE unless I kill it manually. I have looked all over and rewritten the code a few times, and no luck.
import smtplib SMTP_SERVER = 'smtp.gmail.com' SMTP_PORT = 587 sender = '[email protected]' password = '123' recipient = '[email protected]' subject = 'Test Results' body = """** AUTOMATED EMAIL ** \r\n Following are the test results: \r\n""" headers = ["From: " + sender, "Subject: " + subject, "To: " + recipient] headers = "\r\n".join(headers) try: session = smtplib.SMTP(SMTP_SERVER, SMTP_PORT) session.ehlo() session.starttls() session.ehlo() session.login(sender, password) session.sendmail(sender, recipient, headers + "\r\n\r\n" + body) except smtplib.SMTPException: print "Error: Unable to send email." session.quit()
exceptline toexcept smtplib.SMTPException as e:then printe