Created
February 8, 2018 00:28
-
-
Save sc137/1267d6e379da345576ebb31692800b77 to your computer and use it in GitHub Desktop.
send email to one or many people now or in the future
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
#!/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