summaryrefslogtreecommitdiff
path: root/workshop_app/send_mails.py
diff options
context:
space:
mode:
Diffstat (limited to 'workshop_app/send_mails.py')
-rw-r--r--workshop_app/send_mails.py323
1 files changed, 249 insertions, 74 deletions
diff --git a/workshop_app/send_mails.py b/workshop_app/send_mails.py
index 6566041..add55a6 100644
--- a/workshop_app/send_mails.py
+++ b/workshop_app/send_mails.py
@@ -10,11 +10,60 @@ from workshop_portal.settings import (
EMAIL_USE_TLS
)
-def send_email(request, call_on,
+
+def send_smtp_email(request=None, subject=None, message=None,
user_position=None, workshop_date=None,
workshop_title=None, user_name=None,
- other_email=None, phone_number=None
- ):
+ other_email=None, phone_number=None,
+ institute=None, attachment=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
+ msg['Subject'] = subject
+ body = message
+ msg.attach(MIMEText(body, 'plain'))
+
+ if attachment:
+ from django.conf import settings
+ from os import listdir
+ files = listdir(settings.MEDIA_ROOT)
+
+ for f in files:
+ attachment = open(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)
+
+
+ server = SMTP(EMAIL_HOST, EMAIL_PORT)
+ server.ehlo()
+ server.starttls()
+ server.ehlo()
+ server.esmtp_features['auth']='LOGIN DIGEST-MD5 PLAIN'
+ server.login(EMAIL_HOST_USER, EMAIL_HOST_PASSWORD)
+ text = msg.as_string()
+ server.sendmail(EMAIL_HOST_USER, other_email, text)
+ server.close()
+
+
+def send_email( request, call_on,
+ user_position=None, workshop_date=None,
+ workshop_title=None, user_name=None,
+ other_email=None, phone_number=None,
+ institute=None
+ ):
'''
Email sending function while registration and
booking confirmation.
@@ -23,112 +72,238 @@ def send_email(request, call_on,
if call_on == "Registration":
if user_position == "instructor":
message = dedent("""\
- Thank You for Registering on this platform.
- Since you have ask for Instructor Profile,
- we will get back to you soon after verifying your
- profile.
- In case if you don\t get any response within 3days,
- Please contact us at workshops@fossee.in""")
- send_mail(
- "Welcome to FOSSEE", message, EMAIL_HOST_USER,
- [request.user.email], fail_silently=False
+ Your request as an Instructor at FOSSEE, IIT Bombay
+ has been received. You will be notified via email on
+ approval of the same within 3 working days.
+
+ In case of queries regarding the same revert to this
+ email.""")
+
+ try:
+ send_mail(
+ "Instructor Registration - FOSSEE, IIT Bombay", message,
+ EMAIL_HOST_USER, [request.user.email], fail_silently=False
)
+ except Exception:
+ send_smtp_email(request=request,
+ subject="Instructor Registration - FOSSEE, IIT Bombay",
+ message=message, other_email=request.user.email,
+ )
+
- #Send a mail to admin as well as a notification.
+ #Send a mail to admin as well.
message = dedent("""\
- There is a Request for instructor profile on Workshop
- Booking Website from {0} Please get check the profile
- and get back to the user within 2days.
- """.format(request.user))
- send_mail("Instructor Request", message, EMAIL_HOST_USER,
- ['workshops@fossee.in'], fail_silently=False)
+ A new instructor request has been received.
+
+ Instructor name:{0}
+ Instructor email:{1}
+
+ Please verify the profile and mail the user within 2
+ working days.""".format(request.user, request.user.email))
+
+ try:
+ send_mail("New Instructor Registration - FOSSEE, IIT Bombay",
+ message, EMAIL_HOST_USER, ['workshops@fossee.in'],
+ fail_silently=False)
+ except Exception:
+ send_smtp_email(request=request,
+ subject="Instructor Registration - FOSSEE, IIT Bombay",
+ message=message, other_email='workshops@fossee.in',
+ )
else:
message = dedent("""\
- Thank You for Registering on this platform.
- If you face any issue during your session please
- contact us a workshops@fossee.in""")
- send_mail(
- "Welcome to FOSSEE", message, EMAIL_HOST_USER,
+ Thank you for registering as a coordinator with us.
+ Your request as a coordinator has been accepted. You
+ may now proceed to book your dates for the workshop(s).
+
+ In case of queries regarding workshop booking(s),
+ revert to this email.""")
+
+ try:
+ send_mail(
+ "Coordinator Registration at FOSSEE, IIT Bombay", message, EMAIL_HOST_USER,
[request.user.email], fail_silently=False
)
+ except Exception:
+ send_smtp_email(request=request,
+ subject="Coordinator Registration - FOSSEE, IIT Bombay",
+ message=message, other_email=request.user.email,
+ )
elif call_on == "Booking":
if user_position == "instructor":
message = dedent("""\
- You got a workshop booking request from user:{0}, email:{1},
- phone_number:{2} for workshop_title:{3} on date:{4}
- please respond at the earliest""".format(
+ Coordinator name:{0}
+ Coordinator email: {1}
+ Contact number:{2}
+ Institute:{3}
+ Workshop date:{4}
+ Workshop title:{5}
+
+ You may accept or reject this booking
+ workshop.fossee.in .""".format(
user_name, request.user.email,
request.user.profile.phone_number,
- workshop_title, workshop_date
- )
- )
- send_mail(
- "Python Workshop Booking | FOSSEE", message, EMAIL_HOST_USER,
- [other_email], fail_silently=False
+ request.user.profile.institute,
+ workshop_date, workshop_title
+ ))
+
+ try:
+ send_mail(
+ "New FOSSEE Workshop booking on {0}".format(workshop_date),
+ message, EMAIL_HOST_USER, [other_email],
+ fail_silently=False
+ )
+ except Exception:
+ send_smtp_email(request=request,
+ subject="New FOSSEE Workshop booking on {0}"
+ .format(workshop_date),
+ message=message, other_email=other_email,
)
else:
message = dedent("""\
- Thank You for Booking on this platform.
- Here are your workshop details workshop_title:{0}
- workshop_date:{1}, instructor_email:{2},
- instructor phone_number:{3}
- If you face any issue during your session please contact
- respective instructor or fossee at workshops@fossee.in""".format(
- workshop_title, workshop_date,
- other_email, phone_number
- )
- )
- send_mail(
- "Python Workshop Booking | FOSSEE", message, EMAIL_HOST_USER,
+ Thank You for New FOSSEE Workshop booking.
+
+ Workshop date:{0}
+ Workshop title:{1}
+
+ 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
+
+ In case of queries regarding workshop booking(s), revert
+ to this email.""".format(
+ workshop_date, workshop_title
+ ))
+
+ try:
+ send_mail(
+ "Pending Request for New FOSSEE Workshop booking on {0}"
+ .format(workshop_date), message, EMAIL_HOST_USER,
[request.user.email], fail_silently=False
)
+ except Exception:
+ send_smtp_email(request=request,
+ subject="Pending Request for New FOSSEE Workshop booking \
+ on {0}".format(workshop_date),
+ message=message, other_email=request.user.email,
+ )
elif call_on == "Booking Confirmed":
if user_position == "instructor":
message = dedent("""\
- You have confirmed the booking on workshop_date:{0} for
- workshop_title:{1} by coordinator:{2} coordinator_email:{3},
- coordinator_phone_number:{4}"""
- .format(workshop_date, workshop_title, user_name, other_email,
- phone_number))
- send_mail("Python Workshop Booking Confirmation", message, EMAIL_HOST_USER,
- [request.user.email], fail_silently=False)
+ Coordinator name:{0}
+ Coordinator email: {1}
+ Contact number:{2}
+ Institute:{3}
+ Workshop date:{4}
+ Workshop title:{5}
+
+ You have accepted this booking. Detailed instructions have
+ been sent to the coordinator. """.format(user_name, user_name,
+ 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
+ )
else:
message = dedent("""\
- Your workshop on {0} for {1} has been confirmed by the
- instructor please get in touch with the
- instructor {2} - {3} for further assistance""".format(
- workshop_date, workshop_title,
- request.user.email, phone_number))
- send_mail("Python Workshop Booking Confirmation", message, EMAIL_HOST_USER,
- [other_email], fail_silently=False)
+ Instructor name:{0}
+ Instructor email: {1}
+ Contact number:{2}
+ Workshop date:{3}
+ Workshop title:{4}
+
+ Your workshop booking has been accepted. Detailed
+ instructions are attached below.
+
+ In case of queries regarding the workshop
+ instructions/schedule revert to this email.""".format(
+ request.user.username, request.user.email,
+ 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
+ )
elif call_on == "Booking Request Rejected":
if user_position == "instructor":
message = dedent("""\
- You have reject the booking on {0} for {1} by {2}"""
- .format(workshop_date, workshop_title, user_name))
- send_mail("Python Workshop Booking Rejected", message,
- EMAIL_HOST_USER, [request.user.email], fail_silently=False)
+ Coordinator name:{0}
+ Coordinator email: {1}
+ Contact number:{2}
+ Institute:{3}
+ Workshop date:{4}
+ Workshop title:{4}
+
+ You have rejected this booking. The coordinator has
+ been notified.""".format(user_name, other_email,
+ phone_number, institute,
+ workshop_date, workshop_title))
+
+ try:
+ send_mail("FOSSEE Workshop booking rejected for{0}"
+ .format(workshop_date), message, EMAIL_HOST_USER,
+ [request.user.email], fail_silently=False)
+ except Exception:
+ send_smtp_email(request=request,
+ subject="FOSSEE Workshop booking rejected for {0}".
+ format(workshop_date), message=message,
+ other_email=request.user.email
+ )
else:
message = dedent("""\
- Your workshop request on {0}
- has been rejected by the instructor,
- please try for some other day.""".format(workshop_date))
- send_mail("Python Workshop Booking Request Rejected", message,
- EMAIL_HOST_USER, [other_email], fail_silently=False)
+ Workshop date:{0}
+ Workshop title:{1}
+
+ 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))
+
+ try:
+ send_mail("FOSSEE Workshop booking rejected for {0}".
+ format(workshop_date), message, EMAIL_HOST_USER,
+ [other_email], fail_silently=False)
+ except Exception:
+ send_smtp_email(request=request,
+ subject="FOSSEE Workshop booking rejected for {0}".
+ format(workshop_date), message=message,
+ other_email=other_email
+ )
elif call_on =='Workshop Deleted':
message = dedent("""\
- You have deleted a Workshop, scheduled on {0},
- workshop title: {1}"""
- .format(workshop_date, workshop_title))
- send_mail("Python Workshop Deleted", message, EMAIL_HOST_USER,
- [request.user.email], fail_silently=False)
+ You have deleted a Workshop.
+
+ Workshop date:{0}
+ Workshop title:{1}"""
+ .format(workshop_date, workshop_title))
+ try:
+ send_mail("FOSSEE workshop deleted for {0}".format(workshop_date),
+ message, EMAIL_HOST_USER, [request.user.email],
+ fail_silently=False)
+ except Exception:
+ send_smtp_email(request=request,
+ subject="FOSSEE Workshop deleted for {0}".
+ format(workshop_date), message=message,
+ other_email=request.user.email
+ )
else:
message = "Issue at Workshop Booking App please check"
- send_mail("Issue At Workshop Booking App Mailing", message, EMAIL_HOST_USER,
+ 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'
+ )