Skip to content

Instantly share code, notes, and snippets.

@sc137
Created February 8, 2018 00:28
Show Gist options
  • Save sc137/1267d6e379da345576ebb31692800b77 to your computer and use it in GitHub Desktop.
Save sc137/1267d6e379da345576ebb31692800b77 to your computer and use it in GitHub Desktop.
send email to one or many people now or in the future
#!/usr/local/bin/python3
#
# send_o365.py
# /sable cantus/
# http://cantus.us/
###################
"""
Use in a delay_until script to send a timed message.
https://github.com/Narcolapser/python-o365
$ pip3 install O365
Save your credentials as an environment variable in .profile
export o365_email="your_email"
export o365_password="your_password"
"""
import os, time, datetime
from O365 import Message
# set the time to delay until YYYY, MM, DD, HH, MM, SS
delay_until = datetime.datetime(2018, 2, 7, 8, 5, 0)
fromAddr = os.getenv('o365_email')
password = os.getenv('o365_password')
toAddrs = ['jcantus@riohondo.edu']
messageSubject = 'Checking the inbox?'
messageBody = """
Sending messages from python.
/sable
"""
while datetime.datetime.now() < delay_until:
time.sleep(1)
authenticiation = (fromAddr, password)
m = Message(auth=authenticiation)
for i in toAddrs:
m.setRecipients(i)
m.setSubject(messageSubject)
m.setBody(messageBody)
m.sendMessage()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment