Commit 191635f2 authored by Renzo Marini's avatar Renzo Marini

mail arreglado

parent aafe9dff
......@@ -7,6 +7,8 @@ from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
import credentials
import pathlib
import sys
MY_ADDRESS = credentials.MY_ADDRESS
PASSWORD = credentials.PASSWORD
......@@ -20,7 +22,7 @@ def get_contacts(filename):
names = []
emails = []
with open(filename, mode='r', encoding='utf-8') as contacts_file:
with open(filename, mode='r') as contacts_file:
for a_contact in contacts_file:
names.append(a_contact.split()[0])
emails.append(a_contact.split()[1])
......@@ -33,14 +35,15 @@ def read_template(filename):
name specified by filename.
"""
with open(filename, 'r', encoding='utf-8') as template_file:
with open(filename, 'r') as template_file:
template_file_content = template_file.read()
return Template(template_file_content)
def send(script, additional_msg="", log_path=None):
names, emails = get_contacts('contacts.conf') # read contacts
message_template = read_template('message.conf')
mail_dir = str(pathlib.Path(__file__).parent.absolute())
names, emails = get_contacts(mail_dir + '/contacts.conf') # read contacts
message_template = read_template(mail_dir + '/message.conf')
# set up the SMTP server
s = smtplib.SMTP(host='smtp.fing.edu.uy', port=587)
......@@ -77,7 +80,10 @@ def send(script, additional_msg="", log_path=None):
msg.attach(part)
# send the message via the server set up earlier.
s.send_message(msg)
if sys.version_info[0] >= 3:
s.send_message(msg)
else:
s.sendmail(msg["From"], msg["To"], msg.as_string())
del msg
# Terminate the SMTP session and close the connection
......@@ -85,4 +91,4 @@ def send(script, additional_msg="", log_path=None):
if __name__ == '__main__':
send()
send("shn")
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment