diff options
author | prathamesh | 2017-09-01 17:22:29 +0530 |
---|---|---|
committer | prathamesh | 2017-09-01 17:22:29 +0530 |
commit | 1e3bb9e325214be0105f8b907badc84b2dbbeb91 (patch) | |
tree | 3327924e1879524909d5f1603dfe7d3dbda4c05a /yaksh/send_emails.py | |
parent | e2c65655dcdc5558cfb4ab668c3012024d27ac75 (diff) | |
parent | 9e0f737c25a5156aa884d27357af0aef1145c4b7 (diff) | |
download | online_test-1e3bb9e325214be0105f8b907badc84b2dbbeb91.tar.gz online_test-1e3bb9e325214be0105f8b907badc84b2dbbeb91.tar.bz2 online_test-1e3bb9e325214be0105f8b907badc84b2dbbeb91.zip |
Merge branch 'master' of https://github.com/FOSSEE/online_test into improve-code-server
Conflicts Resolved:
yaksh/templates/yaksh/question.html
Diffstat (limited to 'yaksh/send_emails.py')
-rw-r--r-- | yaksh/send_emails.py | 32 |
1 files changed, 31 insertions, 1 deletions
diff --git a/yaksh/send_emails.py b/yaksh/send_emails.py index 24215dd..ae49f23 100644 --- a/yaksh/send_emails.py +++ b/yaksh/send_emails.py @@ -7,11 +7,14 @@ from string import digits, punctuation import hashlib from textwrap import dedent import smtplib +import os # Django imports from django.utils.crypto import get_random_string from django.conf import settings -from django.core.mail import send_mass_mail, send_mail +from django.core.mail import EmailMultiAlternatives, send_mail +from django.core.files.storage import default_storage +from django.core.files.base import ContentFile def generate_activation_key(username): @@ -57,3 +60,30 @@ def send_user_mail(user_mail, key): success = False return success, msg + +def send_bulk_mail(subject, email_body, recipients, attachments): + try: + text_msg = "" + msg = EmailMultiAlternatives(subject, text_msg, settings.SENDER_EMAIL, + recipients + ) + msg.attach_alternative(email_body, "text/html") + if attachments: + for file in attachments: + path = default_storage.save('attachments/'+file.name, + ContentFile(file.read()) + ) + msg.attach_file(os.sep.join((settings.MEDIA_ROOT, path)), + mimetype="text/html" + ) + default_storage.delete(path) + msg.send() + + message = "Email Sent Successfully" + + except Exception as exc_msg: + message = """Error: {0}. Please check email address.\ + If email address is correct then + Please contact {1}.""".format(exc_msg, settings.REPLY_EMAIL) + + return message |