summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--local_settings.py1
-rw-r--r--workshop_app/send_mails.py96
-rw-r--r--workshop_app/templates/workshop_app/my_workshops.html4
-rw-r--r--workshop_portal/settings.py5
4 files changed, 64 insertions, 42 deletions
diff --git a/local_settings.py b/local_settings.py
index 8251c89..940a33e 100644
--- a/local_settings.py
+++ b/local_settings.py
@@ -7,3 +7,4 @@ EMAIL_PORT = 'PORT Number'
EMAIL_HOST_USER = 'your username'
EMAIL_HOST_PASSWORD = 'your password'
EMAIL_USE_TLS = True
+SENDER_EMAIL = 'your email address' \ No newline at end of file
diff --git a/workshop_app/send_mails.py b/workshop_app/send_mails.py
index a8ada76..a4e1e52 100644
--- a/workshop_app/send_mails.py
+++ b/workshop_app/send_mails.py
@@ -3,6 +3,7 @@ __author__ = "Akshen Doke"
from django.core.mail import send_mail
from textwrap import dedent
from random import randint
+from smtplib import SMTP
import hashlib
from django.utils.crypto import get_random_string
from string import punctuation, digits
@@ -16,8 +17,16 @@ from workshop_portal.settings import (
EMAIL_HOST_USER,
EMAIL_HOST_PASSWORD,
EMAIL_USE_TLS,
- PRODUCTION_URL
+ PRODUCTION_URL,
+ SENDER_EMAIL
)
+from django.core.mail import EmailMultiAlternatives
+from django.conf import settings
+from os import listdir, path
+from email.mime.multipart import MIMEMultipart
+from email.mime.text import MIMEText
+from email.mime.base import MIMEBase
+from email import encoders
def generate_activation_key(username):
"""Generates hashed secret key for email activation"""
@@ -34,12 +43,6 @@ def send_smtp_email(request=None, subject=None, message=None,
Send email using SMTPLIB
'''
- from smtplib import SMTP
- from email.mime.multipart import MIMEMultipart
- from email.mime.text import MIMEText
- from email.mime.base import MIMEBase
- from email import encoders
-
msg = MIMEMultipart()
msg['From'] = EMAIL_HOST_USER
msg['To'] = other_email
@@ -101,7 +104,7 @@ def send_email( request, call_on,
try:
send_mail(
"Instructor Registration - FOSSEE, IIT Bombay", message,
- EMAIL_HOST_USER, [request.user.email], fail_silently=False
+ SENDER_EMAIL, [request.user.email], fail_silently=False
)
except Exception:
send_smtp_email(request=request,
@@ -122,7 +125,7 @@ def send_email( request, call_on,
try:
send_mail("New Instructor Registration - FOSSEE, IIT Bombay",
- message, EMAIL_HOST_USER, ['workshops@fossee.in'],
+ message, SENDER_EMAIL, ['workshops@fossee.in'],
fail_silently=False)
except Exception:
send_smtp_email(request=request,
@@ -147,7 +150,7 @@ def send_email( request, call_on,
try:
send_mail(
- "Coordinator Registration at FOSSEE, IIT Bombay", message, EMAIL_HOST_USER,
+ "Coordinator Registration at FOSSEE, IIT Bombay", message, SENDER_EMAIL,
[request.user.email], fail_silently=False
)
except Exception:
@@ -167,17 +170,18 @@ def send_email( request, call_on,
Workshop title:{5}
You may accept or reject this booking
- workshop.fossee.in .""".format(
+ {6}/my_workshops/ .""".format(
user_name, request.user.email,
request.user.profile.phone_number,
request.user.profile.institute,
- workshop_date, workshop_title
+ workshop_date, workshop_title,
+ PRODUCTION_URL
))
try:
send_mail(
"New FOSSEE Workshop booking on {0}".format(workshop_date),
- message, EMAIL_HOST_USER, [other_email],
+ message, SENDER_EMAIL, [other_email],
fail_silently=False
)
except Exception:
@@ -195,17 +199,17 @@ def send_email( request, call_on,
Your request has been received and is awaiting instructor
approval/disapproval. You will be notified about the status
- via email and on your workshops.fossee.in
+ via email and on {2}/my_workshops/
In case of queries regarding workshop booking(s), revert
to this email.""".format(
- workshop_date, workshop_title
+ workshop_date, workshop_title, PRODUCTION_URL
))
try:
send_mail(
"Pending Request for New FOSSEE Workshop booking on {0}"
- .format(workshop_date), message, EMAIL_HOST_USER,
+ .format(workshop_date), message, SENDER_EMAIL,
[request.user.email], fail_silently=False
)
except Exception:
@@ -229,11 +233,21 @@ def send_email( request, call_on,
been sent to the coordinator. """.format(user_name, other_email,
phone_number, institute, workshop_date, workshop_title))
- send_smtp_email(request=request,
- subject="FOSSEE Workshop booking confirmation on {0}".
- format(workshop_date), message=message,
- other_email=request.user.email, attachment=1
- )
+
+ subject = "FOSSEE Workshop booking confirmation on {0}".\
+ format(workshop_date)
+ msg = EmailMultiAlternatives(subject, message, SENDER_EMAIL, [request.user.email])
+
+ files = listdir(settings.MEDIA_ROOT)
+ for f in files:
+ attachment = open(path.join(settings.MEDIA_ROOT,f), 'rb')
+ part = MIMEBase('application', 'octet-stream')
+ part.set_payload((attachment).read())
+ encoders.encode_base64(part)
+ part.add_header('Content-Disposition', "attachment; filename= %s " % f)
+ msg.attach(part)
+ msg.send()
+
else:
message = dedent("""\
Instructor name:{0}
@@ -251,11 +265,20 @@ def send_email( request, call_on,
phone_number, workshop_date, workshop_title
))
- send_smtp_email(request=request,
- subject="FOSSEE Workshop booking confirmation on {0}".
- format(workshop_date), message=message,
- other_email=other_email, attachment=1
- )
+ subject = "FOSSEE Workshop booking confirmation on {0}".\
+ format(workshop_date)
+ msg = EmailMultiAlternatives(subject, message, SENDER_EMAIL, [request.user.email])
+
+ files = listdir(settings.MEDIA_ROOT)
+ for f in files:
+ attachment = open(path.join(settings.MEDIA_ROOT,f), 'rb')
+ part = MIMEBase('application', 'octet-stream')
+ part.set_payload((attachment).read())
+ encoders.encode_base64(part)
+ part.add_header('Content-Disposition', "attachment; filename= %s " % f)
+ msg.attach(part)
+ msg.send()
+
elif call_on == "Booking Request Rejected":
if user_position == "instructor":
@@ -274,7 +297,7 @@ def send_email( request, call_on,
try:
send_mail("FOSSEE Workshop booking rejected for {0}"
- .format(workshop_date), message, EMAIL_HOST_USER,
+ .format(workshop_date), message, SENDER_EMAIL,
[request.user.email], fail_silently=False)
except Exception:
send_smtp_email(request=request,
@@ -290,12 +313,12 @@ def send_email( request, call_on,
We regret to inform you that your workshop booking
has been rejected due to unavailability of the
instructor. You may try booking other available
- slots workshops.fossee.in """
- .format(workshop_date, workshop_title))
+ slots {2}/book/ """
+ .format(workshop_date, workshop_title, PRODUCTION_URL))
try:
send_mail("FOSSEE Workshop booking rejected for {0}".
- format(workshop_date), message, EMAIL_HOST_USER,
+ format(workshop_date), message, SENDER_EMAIL,
[other_email], fail_silently=False)
except Exception:
send_smtp_email(request=request,
@@ -313,7 +336,7 @@ def send_email( request, call_on,
.format(workshop_date, workshop_title))
try:
send_mail("FOSSEE workshop deleted for {0}".format(workshop_date),
- message, EMAIL_HOST_USER, [request.user.email],
+ message, SENDER_EMAIL, [request.user.email],
fail_silently=False)
except Exception:
send_smtp_email(request=request,
@@ -324,11 +347,6 @@ def send_email( request, call_on,
else:
message = "Issue at Workshop Booking App please check"
- try:
- send_mail("Issue At Workshop Booking App Mailing", message, EMAIL_HOST_USER,
- ['doke.akshen@gmail.com', 'mahesh.p.gudi@gmail.com', 'aditya94palaparthy@gmail.com'], fail_silently=False)
- except Exception:
- send_smtp_email(request=request,
- subject="Issue at Workshop Booking App please check",
- message=message, other_email='doke.akshen@gmail.com'
- )
+ send_mail("Issue At Workshop Booking App Mailing", message, SENDER_EMAIL,
+ ['your developer id'], fail_silently=False)
+
diff --git a/workshop_app/templates/workshop_app/my_workshops.html b/workshop_app/templates/workshop_app/my_workshops.html
index 275a0a0..c20a6ca 100644
--- a/workshop_app/templates/workshop_app/my_workshops.html
+++ b/workshop_app/templates/workshop_app/my_workshops.html
@@ -147,7 +147,7 @@
<td>{{ workshop.requested_workshop_date }}</td>
<td><span class = "label label-success">{{ workshop.status }}</span></td>
{% endif %}
- {% if workshop.status == 'ACCEPTED' and workshop.conditionone %}
+ {% if workshop.status == 'ACCEPTED' and workshop.condition_one %}
{% if request.user.profile.position == 'instructor' %}
<td>{{ workshop.proposed_workshop_coordinator }}</td>
{% else %}
@@ -186,7 +186,7 @@
{% for workshop in workshop_occurences %}
<tbody>
<tr>
- {% if workshop.status == 'Pending' and workshop.conditionone %}
+ {% if workshop.status == 'Pending' and workshop.condition_one %}
{% if request.user.profile.position == 'instructor' %}
<td>{{ workshop.proposed_workshop_coordinator }}</td>
{% endif %}
diff --git a/workshop_portal/settings.py b/workshop_portal/settings.py
index 91f4b6a..c0a90df 100644
--- a/workshop_portal/settings.py
+++ b/workshop_portal/settings.py
@@ -17,7 +17,8 @@ from local_settings import (
EMAIL_PORT,
EMAIL_HOST_USER,
EMAIL_HOST_PASSWORD,
- EMAIL_USE_TLS
+ EMAIL_USE_TLS,
+ SENDER_EMAIL
)
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
@@ -148,6 +149,8 @@ EMAIL_HOST_PASSWORD = EMAIL_HOST_PASSWORD
EMAIL_PORT = EMAIL_PORT
EMAIL_USE_TLS = EMAIL_USE_TLS
EMAIL_TIMEOUT = 300
+SENDER_EMAIL = SENDER_EMAIL
+
#EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend' #Temp Solution
#Change this to the production url