Python/SMTP

From Fundamental Ramen
Jump to navigation Jump to search

Send a message.

try:
    with smtplib.SMTP(HOST, PORT, timeout = TIMEOUT) as smtp:
        # smtp.set_debuglevel(2)
        # smtp.starttls()
        # smtp.login(USER, PASS)
        smtp.sendmail(FROM, RCPT, message)
except smtplib.SMTPConnectError:
    # Connection refused.
    pass
except smtplib.SMTPServerDisconnected:
    # Connection reset.
    pass
except:
    # Connection timeout. (not sure)
    pass