diff --git a/config.env.py b/config.env.py index 02caccb1..09c89e3d 100644 --- a/config.env.py +++ b/config.env.py @@ -31,5 +31,12 @@ LDAP_BIND_DN = environ.get("PACKET_LDAP_BIND_DN", None) LDAP_BIND_PASS = environ.get("PACKET_LDAP_BIND_PASS", None) +# Mail Config +MAIL_PROD = environ.get("PACKET_MAIL_PROD", False) +MAIL_SERVER = environ.get("PACKET_MAIL_SERVER", "thoth.csh.rit.edu") +MAIL_USERNAME = environ.get("PACKET_MAIL_USERNAME", "packet@csh.rit.edu") +MAIL_PASSWORD = environ.get("PACKET_MAIL_PASSWORD", None) +MAIL_USE_TLS = environ.get("PACKET_MAIL_TLS", True) + # Slack URL for pushing to #general SLACK_WEBHOOK_URL = environ.get("PACKET_SLACK_URL", None) diff --git a/packet/commands.py b/packet/commands.py index 9a310d98..10d9bb98 100644 --- a/packet/commands.py +++ b/packet/commands.py @@ -7,6 +7,7 @@ import csv import click +from packet.mail import send_mail from . import app, db from .models import Freshman, Packet, FreshSignature, UpperSignature, MiscSignature from .ldap import ldap_get_eboard_role, ldap_get_active_rtps, ldap_get_3das, ldap_get_webmasters, \ @@ -126,10 +127,11 @@ def create_packets(freshmen_csv): # Create the new packets and the signatures for each freshman in the given CSV freshmen_in_csv = parse_csv(freshmen_csv) - print("Creating DB entries...") + print("Creating DB entries and sending emails...") for freshman in Freshman.query.filter(Freshman.rit_username.in_(freshmen_in_csv)).all(): packet = Packet(freshman=freshman, start=start, end=end) db.session.add(packet) + send_mail(packet) for member in all_upper: sig = UpperSignature(packet=packet, member=member.uid) diff --git a/packet/mail.py b/packet/mail.py new file mode 100644 index 00000000..077c6793 --- /dev/null +++ b/packet/mail.py @@ -0,0 +1,19 @@ +from flask import render_template +from flask_mail import Mail, Message + +from packet import app + +mail = Mail(app) + + +def send_mail(packet): + if app.config['MAIL_PROD']: + recipients = ["<" + packet.freshman.rit_username + "@rit.edu>"] + msg = Message(subject="CSH Packet Starts " + packet.start.strftime('%A, %B %-d'), + sender=app.config.get("MAIL_USERNAME"), + recipients=recipients) + + template = 'mail/packet_start' + msg.body = render_template(template + '.txt', packet=packet) + msg.html = render_template(template + '.html', packet=packet) + mail.send(msg) diff --git a/packet/templates/extend/email.html b/packet/templates/extend/email.html new file mode 100644 index 00000000..d9bc5b41 --- /dev/null +++ b/packet/templates/extend/email.html @@ -0,0 +1,18 @@ + + + +{% block head %} +
+Soon you'll starting the introductory process for CSH, and the first part of that is Packet.
+Your packet will start on {{ packet.start.strftime('%A, %B %-d') }} at {{ packet.start.strftime('%-I:%M %p') }}
+You can view your packet at freshmen-packet.csh.rit.edu with + the credentials you should have been sent.
+If you don't know your credentials, reach out to an RTP
+If you have any questions about Packet or the introductory process, email evals@csh.rit.edu
+If you have any questions about login credentials or any technical issues, email rtp@csh.rit.edu
+