diff options
author | adityacp | 2017-04-27 15:29:09 +0530 |
---|---|---|
committer | adityacp | 2017-04-27 15:29:09 +0530 |
commit | 82e30d89fb1814d12a1ee40a0f1b81e164f0ed85 (patch) | |
tree | 39fe6b90c12cbb9ad5dfd12f273ec55844146757 /yaksh/email_verification.py | |
parent | 966fd7f33c67b9d20e42c35bd3825119e3ba066f (diff) | |
download | online_test-82e30d89fb1814d12a1ee40a0f1b81e164f0ed85.tar.gz online_test-82e30d89fb1814d12a1ee40a0f1b81e164f0ed85.tar.bz2 online_test-82e30d89fb1814d12a1ee40a0f1b81e164f0ed85.zip |
Changes in email_verification.py, views.py, forms.py
- Updation of user email if multiple users found with same email
- Update user registration form
- Change email_verification.py to send email
Diffstat (limited to 'yaksh/email_verification.py')
-rw-r--r-- | yaksh/email_verification.py | 27 |
1 files changed, 20 insertions, 7 deletions
diff --git a/yaksh/email_verification.py b/yaksh/email_verification.py index 4eded1c..721fa61 100644 --- a/yaksh/email_verification.py +++ b/yaksh/email_verification.py @@ -4,14 +4,13 @@ try: except ImportError: from string import ascii_letters as letters from string import digits, punctuation -# Local imports import hashlib from random import randint from textwrap import dedent +import smtplib # Django imports from django.utils.crypto import get_random_string -from django.core.mail import send_mail from django.conf import settings def generate_activation_key(username): @@ -27,8 +26,8 @@ def send_user_mail(user_mail, key): """ try: to = user_mail - subject = "Yaksh Email Verification" - msg = dedent("""\ + subject = 'Yaksh Email Verification' + message = dedent("""\ To activate your account and verify your email address, please click the following link: {0}/exam/activate/{1} @@ -41,15 +40,29 @@ def send_user_mail(user_mail, key): """.format(settings.PRODUCTION_URL, key, settings.REPLY_EMAIL) ) - send_mail(subject, msg, settings.SENDER_EMAIL, [to]) + user = settings.EMAIL_HOST_USER + pwd = settings.EMAIL_HOST_PASSWORD + smtpserver = smtplib.SMTP(settings.EMAIL_HOST, settings.EMAIL_PORT) + smtpserver.ehlo() + smtpserver.starttls() + smtpserver.ehlo() + smtpserver.esmtp_features['auth']='LOGIN DIGEST-MD5 PLAIN' + + smtpserver.login(user, pwd) + header = 'To:{0}\nFrom:{1}\nSubject:{2}\n'.format(to, + settings.SENDER_EMAIL, subject) + message = '{0}\n{1}\n\n'.format(header, message) + smtpserver.sendmail(user, to, message) + smtpserver.close() + msg = "An activation link is sent to your registered email.\ Please activate the link within 20 minutes." success = True + except Exception as exc_msg: msg = """Error: {0}. Please check your email address.\ If email address is correct then - Please contact your \ - instructor/administrator.""".format(exc_msg) + Please contact {1}.""".format(exc_msg, settings.REPLY_EMAIL) success = False return success, msg |