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 %} + + CSH Packet + + +{% endblock %} + + +{% block body %} +{% endblock %} + + + diff --git a/packet/templates/mail/packet_start.html b/packet/templates/mail/packet_start.html new file mode 100644 index 00000000..36e2a300 --- /dev/null +++ b/packet/templates/mail/packet_start.html @@ -0,0 +1,15 @@ +{% extends "extend/email.html" %} + +{% block body %} +
+

Hello {{ packet.freshman.name }},

+

Welcome to Computer Science House!

+

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

+
+{% endblock %} diff --git a/packet/templates/mail/packet_start.txt b/packet/templates/mail/packet_start.txt new file mode 100644 index 00000000..012423dc --- /dev/null +++ b/packet/templates/mail/packet_start.txt @@ -0,0 +1,14 @@ +Hello {{ packet.freshman.name }}, + +Welcome to Computer Science House! + +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 diff --git a/requirements.txt b/requirements.txt index 8bd1149f..a8e325fd 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,8 +1,9 @@ Flask~=1.1.0 Flask-pyoidc~=2.2.0 -flask_sqlalchemy==2.3.2 -psycopg2-binary==2.8.3 -Flask-Migrate==2.2.1 -pylint==2.3.1 -gunicorn==19.7.1 -csh_ldap>=2.1.0 +Flask-Mail~=0.9.1 +flask_sqlalchemy~=2.3.2 +psycopg2-binary~=2.8.3 +Flask-Migrate~=2.2.1 +pylint~=2.3.1 +gunicorn~=19.7.1 +csh_ldap~=2.1.0