Created
June 11, 2020 13:34
-
-
Save Jerry0420/4c44e36e24fa08f4f894a3a41338cf73 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from email.message import EmailMessage | |
import smtplib | |
content = '''<html><body><table style="margin-bottom: 0px; border:1px solid #d8d8d8;"><thead><tr><th>Index</th><th>Count</th><th>Del after 6 Hrs</th><th>Rate</th><th>Extension Enable</tr></th></thead><tbody>\n''' | |
for i in alarms: | |
content += '<tr><td>{}</td><td>{:,}</td><td>{:,}</td><td>{}</td><td>{}</td></tr>\n'.format(i[0], i[1], i[2], | |
round(i[2] / i[1], 3), gc_nindex.get(i[0], '')) | |
content += '</tbody></table><table><tr><td>TTL 關掉的 index</td></tr>\n' | |
for i in sweeper.disabled: | |
content += '<tr><td>{}</td></tr>'.format(i) | |
content += '</table>' | |
content += '</body></html>' | |
msg = EmailMessage() | |
msg.set_content(content, subtype='html') | |
msg['Subject'] = 'Crawler Data TTL Alarm ' + datetime.now().strftime('%Y-%m-%d %H:%M:%S') | |
msg['From'] = 'service@funmula.com' | |
msg['To'] = args.m | |
smtp_config = { | |
"server": "localhost", | |
"port": 25 | |
} | |
try: | |
config_file = os.path.join(os.environ['HOME'], 'etc', 'smtp.json') | |
with open(config_file) as fd: | |
smtp_config = json.load(fd) | |
except: | |
pass | |
with smtplib.SMTP(smtp_config['server'], smtp_config['port']) as smtp: | |
smtp.starttls() | |
if 'user' in smtp_config and 'passwd' in smtp_config: | |
smtp.login(smtp_config['user'], smtp_config['passwd']) | |
smtp.send_message(msg) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment