Skip to content
Open

v2.0 #19

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
74 commits
Select commit Hold shift + click to select a range
6f6855b
Ignore PyCharm files
dotbugfix Mar 27, 2019
5956b69
Refactor REST APIs to use class views (flask-classy)
dotbugfix Mar 27, 2019
f305495
Fix Flask runtime errors
dotbugfix Mar 29, 2019
d7d4829
Integrate new URLs with frontend
dotbugfix Mar 29, 2019
4c68bad
Create new Angular project for v2
dotbugfix Apr 20, 2019
0f6d43c
Add MaterialUI components
dotbugfix Apr 20, 2019
bc98ac1
Add top-level stepper
dotbugfix Apr 20, 2019
f0546c7
Create attachments page
dotbugfix Apr 20, 2019
eac1cae
Added PDF viewer
dotbugfix Apr 20, 2019
693e1c9
Add PDF rotation buttons
dotbugfix Apr 20, 2019
a78904b
Added WittyMail_ClassDiagram.drawio
dotbugfix Apr 22, 2019
c558894
Added PNG for WittyMail_ClassDiagram.png
dotbugfix Apr 22, 2019
0cf6f86
Update WittyMail_ClassDiagram.drawio
dotbugfix Apr 22, 2019
b1ced45
Add attachment upload step
dotbugfix Apr 22, 2019
cc09540
Add summary step
dotbugfix Apr 22, 2019
954efb3
Add logger service
dotbugfix Apr 23, 2019
9bbce77
Create sleletons for other components
dotbugfix Apr 23, 2019
720d13c
Create app-level menu
dotbugfix Apr 23, 2019
4f944b2
Add about dialog
dotbugfix Apr 23, 2019
93202f7
Added backend REST client and wired up to About dialog
dotbugfix Apr 23, 2019
7303402
Merge remote-tracking branch 'origin/v2.0' into v2.0
dotbugfix Apr 23, 2019
54e7206
Added skeleton
ajaynair Apr 22, 2019
a77f314
Merge branch 'v2.0' of https://github.com/YAO-yet-another-organizatio…
ajaynair Apr 23, 2019
2e7e23e
Sponsor List page design
dotbugfix Apr 27, 2019
7673aff
Column selector UI
dotbugfix Apr 27, 2019
7687dc4
Email subject template with click-to-inset columns
dotbugfix Apr 27, 2019
1306b5d
Email contents rich text editor
dotbugfix Apr 27, 2019
7276c30
Implement Error Dialog as MatSnackBar
dotbugfix May 1, 2019
5aa78b2
Connect sheet upload to backend
dotbugfix May 1, 2019
01538a6
Connect the sponsor-list page to the backend
dotbugfix May 1, 2019
5db6b76
Merge pull request #22 from Saraswitty/backend
dotbugfix May 1, 2019
4b21210
Make things work after the merge
dotbugfix May 1, 2019
523c856
Add main stepper ref to all pages
dotbugfix May 1, 2019
3cb228b
Connect attachment upload to backend
dotbugfix May 1, 2019
f0ba0fe
Add error handling for upload failures
dotbugfix May 1, 2019
875b79f
Connect PDF rotation to backend
dotbugfix May 1, 2019
ca8f5ab
Support to save attachments and extended excel rows
ajaynair May 1, 2019
965a862
Resolved merge conflict
ajaynair May 1, 2019
cba126a
Populate table in email design page on view
dotbugfix May 2, 2019
3339ff8
Allow navigating non-linearly in the main stepper
dotbugfix May 2, 2019
3e5bbbf
Post column mappings to the backend on step 1
dotbugfix May 2, 2019
64a0ab8
Added code to support column mapping
ajaynair May 2, 2019
dd16995
Solved merge conflicts
ajaynair May 2, 2019
ef7afab
Realtime insert and template-to-reality for subject and body
dotbugfix May 2, 2019
ef479ce
E-mail server input form
dotbugfix May 3, 2019
441798d
Populate sheet contents from backend
dotbugfix May 3, 2019
e0a6830
Connect backend for candidate selection
dotbugfix May 3, 2019
d1ea6b2
Bug fixes
ajaynair May 4, 2019
321ac53
Solved merge conflicts
ajaynair May 4, 2019
5f23aba
Added code to support subject and body template
ajaynair May 4, 2019
b90208b
Added support to send test emails
ajaynair May 4, 2019
8eeb2ad
Fix payload in REST API calls
dotbugfix May 4, 2019
f2d9ca7
Modified ColumnMappings to map column_names to header index and heade…
ajaynair May 4, 2019
dde020a
Added support for subject and body template
ajaynair May 4, 2019
6c2beaf
Added button to post email subject/body templates to backend
dotbugfix May 5, 2019
f870394
Solved test email issues
ajaynair May 5, 2019
3acd6b5
Create summary page
dotbugfix May 10, 2019
0be5ad8
Add email viewer dialog
dotbugfix May 10, 2019
14a0d3a
Added support for multiple attachments for a row
ajaynair May 10, 2019
b42035e
Merge branch 'v2.0' of https://github.com/YAO-yet-another-organizatio…
ajaynair May 10, 2019
8691255
Added support for multiple attachments upload
ajaynair May 10, 2019
f4ce0ae
Add column-wise sorting to summary table
dotbugfix May 10, 2019
24dbad8
Add vertical scrollbar to attachment candidates list
dotbugfix May 10, 2019
7d381b1
Remove 'summary' step from attachments view and add a 'next' button i…
dotbugfix May 10, 2019
479946f
Added support to send headers and extended_headers separately
ajaynair May 10, 2019
809b842
Merge branch 'v2.0' of https://github.com/YAO-yet-another-organizatio…
ajaynair May 10, 2019
39a1e23
Connect backend to 'send email' button
dotbugfix May 10, 2019
71f06f2
Merge remote-tracking branch 'origin/v2.0' into v2.0
dotbugfix May 10, 2019
d8b631d
Connect backend to 'send selected emails'
dotbugfix May 10, 2019
e4233fa
Solved a minor issue
ajaynair May 10, 2019
6adba27
Merge remote-tracking branch 'origin/v2.0' into v2.0
dotbugfix May 10, 2019
d677a11
Added button to download sheet
dotbugfix May 10, 2019
893086f
Added index to be passed inbetween front and backend
ajaynair May 10, 2019
51bb745
Improved logging
ajaynair May 13, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ wittymail_ve/

# VS Code
.vscode/
.idea/

# WittyMail log file
wittymail_log.txt
wittymail_log.txt
28 changes: 28 additions & 0 deletions backend/EmailProviderTest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from mailer.Email import Email
from mailer.EmailProvider import EmailProvider
import sys

'''
Basic Test1
-----------
1. Get username and password from CLI
2. Login using SMTP
3. Send a basic email
4. Logout
'''
def basic_test1(username, password):
e = Email([username], [username], 'Subject', 'Body')
eP = EmailProvider()
selected_eP = eP.choose_email_provider("SMTP")
seP = selected_eP(username, 'smtp.gmail.com', 587, username, password)
seP.login()
seP.send_email(e)
seP.logout()

if __name__ == '__main__':
if len(sys.argv) != 3:
print("EmailProviderTest.py <username> <password>")

username = sys.argv[1]
password = sys.argv[2]
basic_test1(username, password)
41 changes: 41 additions & 0 deletions backend/mailer/Email.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/usr/bin/env python
# coding=utf-8

import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.mime.base import MIMEBase
from email import encoders
import os
import util.logger as logger

log = logger.get_logger(__name__)

class Email():
subject_template = None
body_template = None
frm = None
common_attachment_dir = None

def __init__(self, tos, ccs, attachments, subject, body, status = None):
assert tos is not None, log.error('Incorrect value provided to=%s cc=%s' % (tos, ccs))
self.tos = tos
self.ccs = ccs
self.attachments = attachments
self.subject = subject
self.body = body
self.status = status

def get_email_from(self):
return Email.frm

def set_email_frm(self, frm):
Email.frm = frm

def set_email_common_attachment_dir(self, attachment_dir):
Email.common_attachment_dir = attachment_dir

def __del__(self):
self.to = None
Email.subject_template = None
Email.body_template = None
19 changes: 19 additions & 0 deletions backend/mailer/EmailProvider.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import importlib
import pdb
#from mailer.SMTPEmailProvider import SMTPEmailProvider

class EmailProvider:
def __init__(self):
pass

def choose_email_provider(self, name):
from mailer.SMTPEmailProvider import SMTPEmailProvider
return SMTPEmailProvider

def login(self):
raise NotImplementedError()
def send_email(self):
raise NotImplementedError()
def logout(self):
raise NotImplementedError()

107 changes: 107 additions & 0 deletions backend/mailer/SMTPEmailProvider.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
#!/usr/bin/env python
# coding=utf-8

import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.mime.base import MIMEBase
from email import encoders
import os
import util.logger as logger
from mailer.EmailProvider import EmailProvider
from os import listdir
from os.path import isfile
import pdb

log = logger.get_logger(__name__)

class SMTPEmailProvider(EmailProvider):
def __init__(self, server, port, username, password):
EmailProvider.__init__(self)
assert server is not None and port is not None and username is not None and password is not None,\
log.error('server, port number, username or password is None')

self.server = server
self.port = port
self.username = username
self.password = password
self.s = None

def logout(self):
self.s.quit()
log.debug('emailapi teardown successful')

# TODO Can you check if SMTPlib has different types of Exception (*Error) classes and write an except block for each?
def login(self):
# Connect to the SMTP server and login
try:
self.s = smtplib.SMTP(self.server, self.port)
self.s.ehlo()
self.s.starttls()
self.s.login(self.username, self.password)

except:
log.exception('Incorrect server/user information provided')
return [-1, 'Incorrect server/user information provided']

log.debug('Login successful')
return [0, 'Login successful']

def send_email(self, e):
try:
# Extra <p> tags show up as multiple line breaks in the resulting email, so replace them
# with single line breaks
body = e.body.replace('</p><p>', '<br />')

log.debug("Cleaned body: %s", body)

msg = MIMEMultipart()
msg['From'] = e.frm
msg['To'] = ", ".join(e.tos)

ccs_to_send = []
if e.ccs is not None and e.ccs[0] != 'None':
msg['Cc'] = ", ".join(e.ccs)
for cc in e.ccs:
ccs_to_send.append(cc.strip())
else:
log.debug('No cc mailer provided')

msg['Subject'] = e.subject
msg.attach(MIMEText(e.body, 'html'))

common_attachments = listdir(e.common_attachment_dir)
common_attachments = [os.path.join(e.common_attachment_dir, ca) for ca in common_attachments]

attachments_dir = os.path.dirname(e.common_attachment_dir)
attachments = [os.path.join(attachments_dir, a) for a in e.attachments]

attachments = attachments + common_attachments

if (attachments is not None):
for attachment in attachments:
if not os.path.isfile(attachment):
return [-1, 'Attachment not found']
try:
a = open(attachment, "rb")
except:
log.exception("Failed to open attachment: %s", attachment)
raise
p = MIMEBase('application', 'octet-stream')
p.set_payload((a).read())
encoders.encode_base64(p)
p.add_header('Content-Disposition', "attachment; filename= %s" % os.path.basename(attachment))
msg.attach(p)

msg_str = msg.as_string()
log.debug("ccs_to_send: %s", ccs_to_send)
if ccs_to_send:
self.s.sendmail(msg['From'], e.tos + ccs_to_send, msg_str)
else:
self.s.sendmail(msg['From'], e.tos, msg_str)
log.info('Email sent by %s to %s' % (msg['From'], msg['To']))
return [0, 'Email sent successfully']
except:
self.login()
log.exception("Failed to send email")
return [-1, 'Error']
136 changes: 0 additions & 136 deletions backend/mailer/emailapi.py

This file was deleted.

Loading