Python/SMTP: Difference between revisions
< Python
Jump to navigation
Jump to search
(Created page with "<source lang="python"> try: HOST = self.config['smtp_host'] PORT = self.config['smtp_port'] TIMEOUT = self.config['smtp_timeout'] with...") |
No edit summary |
||
| (8 intermediate revisions by the same user not shown) | |||
| Line 1: | Line 1: | ||
= Send a message. = | |||
<source lang="python"> | <source lang="python"> | ||
try: | 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 | |||
</source> | </source> | ||
Latest revision as of 09:49, 5 June 2018
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