Skip to content

Instantly share code, notes, and snippets.

@a9QrX3Lu
Last active June 13, 2021 11:27
Show Gist options
  • Select an option

  • Save a9QrX3Lu/7873552558e350d9405f989087266028 to your computer and use it in GitHub Desktop.

Select an option

Save a9QrX3Lu/7873552558e350d9405f989087266028 to your computer and use it in GitHub Desktop.
Notification for a finished long-running job
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
SERVER = "smtp.office365.com"
PORT = "587"
FROM = "wzl574402791@outlook.com"
TO = ["zl31wang@gmail.com"]
SUBJECT = "A job finished"
TEXT = "Hi! A job finished. Please take a look."
message = """From: %s\r\nTo: %s\r\nSubject: %s\r\n\
%s
""" % (FROM, ", ".join(TO), SUBJECT, TEXT)
import smtplib
from pathlib import Path
server = smtplib.SMTP(SERVER, PORT)
with open(f'{Path.home()}/.outlook', 'r') as f:
code = f.readline()
server.starttls()
server.login(FROM, code)
server.sendmail(FROM, TO, message)
server.quit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment