Skip to content

Commit 057714d

Browse files
authored
Merge pull request #145 from devinmatte/mail
Send an email when the packet is generated
2 parents 822a75d + 0076d38 commit 057714d

File tree

7 files changed

+83
-7
lines changed

7 files changed

+83
-7
lines changed

config.env.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,12 @@
3131
LDAP_BIND_DN = environ.get("PACKET_LDAP_BIND_DN", None)
3232
LDAP_BIND_PASS = environ.get("PACKET_LDAP_BIND_PASS", None)
3333

34+
# Mail Config
35+
MAIL_PROD = environ.get("PACKET_MAIL_PROD", False)
36+
MAIL_SERVER = environ.get("PACKET_MAIL_SERVER", "thoth.csh.rit.edu")
37+
MAIL_USERNAME = environ.get("PACKET_MAIL_USERNAME", "[email protected]")
38+
MAIL_PASSWORD = environ.get("PACKET_MAIL_PASSWORD", None)
39+
MAIL_USE_TLS = environ.get("PACKET_MAIL_TLS", True)
40+
3441
# Slack URL for pushing to #general
3542
SLACK_WEBHOOK_URL = environ.get("PACKET_SLACK_URL", None)

packet/commands.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import csv
88
import click
99

10+
from packet.mail import send_mail
1011
from . import app, db
1112
from .models import Freshman, Packet, FreshSignature, UpperSignature, MiscSignature
1213
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):
126127

127128
# Create the new packets and the signatures for each freshman in the given CSV
128129
freshmen_in_csv = parse_csv(freshmen_csv)
129-
print("Creating DB entries...")
130+
print("Creating DB entries and sending emails...")
130131
for freshman in Freshman.query.filter(Freshman.rit_username.in_(freshmen_in_csv)).all():
131132
packet = Packet(freshman=freshman, start=start, end=end)
132133
db.session.add(packet)
134+
send_mail(packet)
133135

134136
for member in all_upper:
135137
sig = UpperSignature(packet=packet, member=member.uid)

packet/mail.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
from flask import render_template
2+
from flask_mail import Mail, Message
3+
4+
from packet import app
5+
6+
mail = Mail(app)
7+
8+
9+
def send_mail(packet):
10+
if app.config['MAIL_PROD']:
11+
recipients = ["<" + packet.freshman.rit_username + "@rit.edu>"]
12+
msg = Message(subject="CSH Packet Starts " + packet.start.strftime('%A, %B %-d'),
13+
sender=app.config.get("MAIL_USERNAME"),
14+
recipients=recipients)
15+
16+
template = 'mail/packet_start'
17+
msg.body = render_template(template + '.txt', packet=packet)
18+
msg.html = render_template(template + '.html', packet=packet)
19+
mail.send(msg)

packet/templates/extend/email.html

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
4+
{% block head %}
5+
<head>
6+
<title>CSH Packet</title>
7+
<link rel="stylesheet"
8+
href="https://assets.csh.rit.edu/csh-material-bootstrap/4.3.1/dist/csh-material-bootstrap.min.css"
9+
media="screen">
10+
</head>
11+
{% endblock %}
12+
13+
<body>
14+
{% block body %}
15+
{% endblock %}
16+
17+
</body>
18+
</html>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{% extends "extend/email.html" %}
2+
3+
{% block body %}
4+
<div class="container main">
5+
<h2>Hello {{ packet.freshman.name }},</h2>
6+
<h3>Welcome to Computer Science House!</h3>
7+
<p>Soon you'll starting the introductory process for CSH, and the first part of that is Packet.</p>
8+
<p>Your packet will start on <span class="badge">{{ packet.start.strftime('%A, %B %-d') }} at {{ packet.start.strftime('%-I:%M %p') }}</span></p>
9+
<p>You can view your packet at <a href="https://freshen-packet.csh.rit.edu">freshmen-packet.csh.rit.edu</a> with
10+
the credentials you should have been sent.</p>
11+
<p>If you don't know your credentials, reach out to an <a href="mailto:[email protected]">RTP</a></p>
12+
<p>If you have any questions about Packet or the introductory process, email <a href="mailto:[email protected]">[email protected]</a></p>
13+
<p>If you have any questions about login credentials or any technical issues, email <a href="mailto:[email protected]">[email protected]</a></p>
14+
</div>
15+
{% endblock %}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
Hello {{ packet.freshman.name }},
2+
3+
Welcome to Computer Science House!
4+
5+
Soon you'll starting the introductory process for CSH, and the first part of that is Packet.
6+
7+
Your packet will start on {{ packet.start.strftime('%A, %B %-d') }} at {{ packet.start.strftime('%-I:%M %p') }}
8+
9+
You can view your packet at freshmen-packet.csh.rit.edu with the credentials you should have been sent.
10+
If you don't know your credentials, reach out to an RTP
11+
12+
If you have any questions about Packet or the introductory process, email [email protected]
13+
14+
If you have any questions about login credentials or any technical issues, email [email protected]

requirements.txt

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
Flask~=1.1.0
22
Flask-pyoidc~=2.2.0
3-
flask_sqlalchemy==2.3.2
4-
psycopg2-binary==2.8.3
5-
Flask-Migrate==2.2.1
6-
pylint==2.3.1
7-
gunicorn==19.7.1
8-
csh_ldap>=2.1.0
3+
Flask-Mail~=0.9.1
4+
flask_sqlalchemy~=2.3.2
5+
psycopg2-binary~=2.8.3
6+
Flask-Migrate~=2.2.1
7+
pylint~=2.3.1
8+
gunicorn~=19.7.1
9+
csh_ldap~=2.1.0

0 commit comments

Comments
 (0)